mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DBAL-1163: Pagination issue with order by statement #4426
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Mar 5, 2015).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user vaheshadunts:
For example I have 2 entities (family, person) with ManyToOne(familyId) association in Person entity, and OneToMany(mappedBy="familyId") in Family Entity (Full class definitions are in the end of description)
And this is my DQL part
This is working perfectly when the ordered firstNames are from different families.
But the paginator class generates 3 queries, 1st for fetching count, second for id's 3rd is a general query for data.
This is the 2nd Query:
SELECT DISTINCT id0, first_name3
FROM (
SELECT f0_.id AS id0, f0_.name AS name1, p1_.id AS id2, p1_.first_name AS first_name3, p1_.last_name AS last_name4
FROM family f0_
INNER JOIN person p1* ON f0_.id = p1_.family_id
ORDER BY p1_.first*name ASC
)dctrn_result
ORDER BY first_name3 ASC
LIMIT 2
So in the select statement in this query there are distinctly selected 2 fields, id and first_name.
And if we'll have 2 people in one family which names are Aaron and Abraham, this query result will be
id | name
1 | Aaron
1 | Abraham
So we have fetched only one id from families instead of 2, which we wanted to select.
Then the where statement of 3rd query will be where id in ( ? ) with params [1,1], and we are getting 1 Family instead of 2.
class Family
{
/****
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}
class Person
{
/****
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}