You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this issue today. The problem is that when you are using FindAndCountAll with a left join (include with require != true), it is left out of the "count" query. Thus when trying to set where: { 'JoinedTable.column': 'something' } the joined column is absent (because the table is not joined during counting) and the query fails.
When calling with a 'where JoinedTable.column' on the parent query:
SELECT `Official`.*
FROM (SELECT Count(`Official`.`id`) AS `count`,
`Official`.`id` AS `id`
FROM `officials` AS `Official`
WHERE `HeadOfficialGames`.`id` IS NULL) AS `Official`
LEFT OUTER JOIN `games` AS `HeadOfficialGames`
ON `Official`.`id` = `HeadOfficialGames`.`headofficialid`;
This errors because in the context of the subquery the joined column is not present.
When calling with 'where column' on the include query:
SELECT `Official`.*
FROM (SELECT Count(`Official`.`id`) AS `count`,
`Official`.`id` AS `id`
FROM `officials` AS `Official`) AS `Official`
LEFT OUTER JOIN `games` AS `HeadOfficialGames`
ON `Official`.`id` = `HeadOfficialGames`.`headofficialid`
AND `HeadOfficialGames`.`headofficialid` IS NULL;
Produces:
"message": "ER_MIX_OF_GROUP_FUNC_AND_FIELDS: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'eventlink.Official.id'; this is incompatible with sql_mode=only_full_group_by"
In short, there's no way to pull of a "where relationship does not exist" in a count query.
Activity
mickhansen commentedon Dec 4, 2014
You can either use
Or
mithrandirii commentedon Dec 4, 2014
my problem is that both results in an inner join, but i need an left join
maybe we could use an option to turn off the new findAndCount feature to exlude the models ?
mickhansen commentedon Dec 4, 2014
Perhaps:
Then it will be used to include filtered projects on the main table but won't affect the count.
yepp4you commentedon Dec 7, 2014
In the case of that order model is same where model,
SQL error is happen in order clause ( ER_BAD_FIELD_ERROR... )
example)
select ... from (select ... where a.xxx ... limit 20) ... left outter join .... order by a.xxx desc
How can i resolve?
mickhansen commentedon Dec 7, 2014
@yepp4you We need more information than that, not really sure what you're describing here.
janmeier commentedon Apr 27, 2015
No more information gotten, closing
jocull commentedon Jan 21, 2016
I ran into this issue today. The problem is that when you are using
FindAndCountAllwith a left join (include with require != true), it is left out of the "count" query. Thus when trying to setwhere: { 'JoinedTable.column': 'something' }the joined column is absent (because the table is not joined during counting) and the query fails.jocull commentedon Jan 21, 2016
Further, using
.count(opts)seems to malform:When calling with a 'where JoinedTable.column' on the parent query:
This errors because in the context of the subquery the joined column is not present.
When calling with 'where column' on the include query:
Produces:
In short, there's no way to pull of a "where relationship does not exist" in a count query.