how to limit the result grouped by the relationship Entity in Doctrine
up vote
0
down vote
favorite
Based on my example I try to get the last 5 comments from a Comment Entity, but only one comment for each Post Entity which is related to the Comment Entity.
Before I asked, I researched, but what I found here didn't make anything clear and didn't work either.
This my current query:
$lastComments = $this->em->getRepository('App:Comment')
->createQueryBuilder('c')
->select('p', 'c')
->leftJoin('c.post', 'p', 'WITH','p.id = c.post')
->andWhere('c.approved = :approved')->setParameter('approved', true)
->groupBy('p.id')
->orderBy("c.createdAt","desc")
->setMaxResults(5)
->getQuery()
->getResult();
Grouping the Post entity directly with groupBy throws me this error:
Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'symadmin.c0_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by").
mysql doctrine
add a comment |
up vote
0
down vote
favorite
Based on my example I try to get the last 5 comments from a Comment Entity, but only one comment for each Post Entity which is related to the Comment Entity.
Before I asked, I researched, but what I found here didn't make anything clear and didn't work either.
This my current query:
$lastComments = $this->em->getRepository('App:Comment')
->createQueryBuilder('c')
->select('p', 'c')
->leftJoin('c.post', 'p', 'WITH','p.id = c.post')
->andWhere('c.approved = :approved')->setParameter('approved', true)
->groupBy('p.id')
->orderBy("c.createdAt","desc")
->setMaxResults(5)
->getQuery()
->getResult();
Grouping the Post entity directly with groupBy throws me this error:
Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'symadmin.c0_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by").
mysql doctrine
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Based on my example I try to get the last 5 comments from a Comment Entity, but only one comment for each Post Entity which is related to the Comment Entity.
Before I asked, I researched, but what I found here didn't make anything clear and didn't work either.
This my current query:
$lastComments = $this->em->getRepository('App:Comment')
->createQueryBuilder('c')
->select('p', 'c')
->leftJoin('c.post', 'p', 'WITH','p.id = c.post')
->andWhere('c.approved = :approved')->setParameter('approved', true)
->groupBy('p.id')
->orderBy("c.createdAt","desc")
->setMaxResults(5)
->getQuery()
->getResult();
Grouping the Post entity directly with groupBy throws me this error:
Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'symadmin.c0_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by").
mysql doctrine
Based on my example I try to get the last 5 comments from a Comment Entity, but only one comment for each Post Entity which is related to the Comment Entity.
Before I asked, I researched, but what I found here didn't make anything clear and didn't work either.
This my current query:
$lastComments = $this->em->getRepository('App:Comment')
->createQueryBuilder('c')
->select('p', 'c')
->leftJoin('c.post', 'p', 'WITH','p.id = c.post')
->andWhere('c.approved = :approved')->setParameter('approved', true)
->groupBy('p.id')
->orderBy("c.createdAt","desc")
->setMaxResults(5)
->getQuery()
->getResult();
Grouping the Post entity directly with groupBy throws me this error:
Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'symadmin.c0_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by").
mysql doctrine
mysql doctrine
asked yesterday
jcarlosweb
191419
191419
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349263%2fhow-to-limit-the-result-grouped-by-the-relationship-entity-in-doctrine%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown