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

[BUG] В QueryBuilder не работает DISTINCT #2250

Closed
scarbo87 opened this issue Mar 28, 2014 · 3 comments
Closed

[BUG] В QueryBuilder не работает DISTINCT #2250

scarbo87 opened this issue Mar 28, 2014 · 3 comments

Comments

@scarbo87
Copy link

$this->modelsManager->createBuilder()
->distinct(true)
->columns([ 'pt.*'])
->addFrom('Pin\Model\PinsTags', 'pt')
->getQuery()
->execute();
SQL Statement: SELECT pins_tags.id, pins_tags.pin_id, pins_tags.tag_id FROM pins_tags

$phql = 'SELECT DISTINCT [Pin\Model\PinsTags].* FROM [Pin\Model\PinsTags]';
$this->modelsManager->executeQuery($phql);
SQL Statement: SELECT pins_tags.id, pins_tags.pin_id, pins_tags.tag_id FROM pins_tags

Судя по коду - https://github.com/phalcon/cphalcon/blob/master/ext/mvc/model/query/builder.c#L1525
если передавать true/false, то на выходе получим SELECT DISTINCT/SELECT ALL, но чтобы я туда не передавал, на выходе только SELECT.

@scarbo87 scarbo87 changed the title В QueryBuilder не работает DISTINCT [BUG] В QueryBuilder не работает DISTINCT Mar 28, 2014
phalcon pushed a commit that referenced this issue Apr 1, 2014
Fix #2250 Updated Phalcon\Db\Dialect::select
@dreamsxin
Copy link
Contributor

Could you try again compiling from the 1.3.2 branch?

@scarbo87
Copy link
Author

scarbo87 commented Apr 2, 2014

Thank you, in 1.3.2 branch DISTINCT it works.
Example:
$this->modelsManager->createBuilder()
->distinct(true)
->columns('t.*')
->addFrom('Pin\Model\Tags', 't')
->join('Pin\Model\PinsTags', null, 'pt')
->join('Pin\Model\Pins', 'p.id = pt.pin_id', 'p')
->where('p.status = 1')
->orderBy('t.weight')
->getQuery()
->execute();
SQL Statement: SELECT DISTINCT t.id, t.slug, t.name, t.weight, t.created_at, t.changed_at FROM tags AS t INNER JOIN pins_tags AS pt ON t.id = pt.tag_id INNER JOIN pins AS p ON p.id = pt.pin_id WHERE p.status = 1 ORDER BY t.weight

$phql = 'SELECT DISTINCT [Pin\Model\PinsTags].* FROM [Pin\Model\PinsTags]';
$this->modelsManager->executeQuery($phql);
SQL Statement: SELECT DISTINCT pins_tags.id, pins_tags.pin_id, pins_tags.tag_id FROM pins_tags

@flinux
Copy link

flinux commented Apr 12, 2014

Nice work guys! I was waiting for the resolution of this problem 👍

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

4 participants