Phalcon:如何获得与众不同的模型? [英] Phalcon: how to get distinct models?

查看:81
本文介绍了Phalcon:如何获得与众不同的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Phalcon模型,如何在获取时获得不同的行使用find()方法的行.

Using Phalcon Model, how can I get distinct rows when get rows using the find() method.

推荐答案

使用构建器:

后面的示例的基本实现:

Basic implementation for later example:

    $queryBuilder = $this->getDI()->getModelsManager()
        ->createBuilder()
        ->addFrom('tableName', 't');

不同的命令:

    $queryBuilder->distinct('t.id');

专栏的东西也可以,但是不推荐:

Column thing works too, but not recommended:

    $queryBuilder->columns('DISTINCT(t.id) AS id')

严格使用模型:

   // we are waiting for it, but may still not be implemented
   TableModel::find(array('distinct' => 'id'))

要计数:

   TableModel::count(array("distinct" => "id"));

根据先前的答案,不那么推荐的方法:

And less recommended way according to previous answer:

   TableModel::find(array('columns' => 'distinct(id)'))

并链接到imo最佳文档.

此外, Phalcon 2.0.2 中也存在一些问题.

Also, there are some issues in Phalcon 2.0.2.

这篇关于Phalcon:如何获得与众不同的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆