phalcon按相关模型列排序

时间:2015-04-08 16:11:35

标签: mysql phalcon

我想从相关表格users中的viewed列订购的表profiles中获取记录。关键是我想以模型方式做到这一点。

我只想写下面的查询并获得模型。 查询:

SELECT * FROM users JOIN profiles ON users.id = profiles.user_id ORDER BY profiles.viewed DESC

1 个答案:

答案 0 :(得分:0)

看我的例子

$Users = \User::query()
        ->leftJoin('UserDependence')
        ->where(implode(" AND ", $conditions))
        ->bind($parameters)
        ->orderBy("User.id DESC")
        ->bindTypes([
            "email" => Column::BIND_PARAM_STR,
            "active" => Column::BIND_PARAM_BOOL,
            "tags"  => Column::BIND_PARAM_STR
        ])
        ->execute();

    $paginator   = new PaginatorModel(
        array(
            "data"  => $Users,
            "limit" => 10,
            "page"  => (int) $this->request->get("page")
        )
    );