Skip to content

Implement distinct/setDistinct on Phalcon\Mvc\Model\Criteria like on query builder #10536

Closed
@williamokano

Description

@williamokano

You guys could add the Distinct from the QueryBuilder into the Phalcon\Mvc\Model\Criteria

I think that it's more practical to do MyModel::query() instead of creating the whole query from the query builder.

As I could see, there's no Distinct method on the Criteria class.

Example: https://gist.github.com/williamokano/a17cb07d791da65bc997

I could use just ->distinct(true) and my problem was solved.

Hi guys, I was wondering if is possible to get distinct values with a query built with the model criteria.

Follow an example (PS.: don't bother with the lack of the bind parameter, it was just a test):

https://gist.github.com/williamokano/a17cb07d791da65bc997

In this case, when I have 1 user that already lived on a city A (id=1) and on a city B (id=2) I will get the user twice (or more, that depends on how many cities he lived).

I know that it's caused because of the intermediate table called lived, and I get the same problem creating "raw queries". But in raw queries I can add the DISTINCT clause and I couldn't find how to do that with the Criteria class.

PS.: I know that if I use the query builder I can set distinct(true) and my problem is solved, but my question is exactly on how to use distinct with Criteria and not with the QueryBuilder.

Regards and apologies about the bad english.

https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Criteria.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions