Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
williamokano opened this issue Jun 23, 2015 · 3 comments

Comments

@williamokano
Copy link

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

@williamokano williamokano changed the title Improvement Add distinct/setDistinct on Phalcon\Mvc\Model\Criteria Jun 23, 2015
@williamokano williamokano changed the title Add distinct/setDistinct on Phalcon\Mvc\Model\Criteria Implement distinct/setDistinct on Phalcon\Mvc\Model\Criteria like on query builder Jun 23, 2015
@KorsaR-ZN
Copy link
Contributor

@williamokano see #10538

@williamokano
Copy link
Author

Thanks, I didn't found this issue. Closed and waiting for the merge :)

Thanks @KorsaR-ZN 👍

Actually, I'll let this open 'til the merge.

@williamokano
Copy link
Author

Feature merged!

Thanks @KorsaR-ZN!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants