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
{{ message }}
Repository navigation
Model.count returning NaN because Mysql returns an empty string #3019
Model.count is returning NaN because Mysql returns an empty string when grouping.
SELECTcount(*) AS`count`FROM`Model`AS`Model`WHERE (`Model`.`deleted_at` IS NULLAND`Model`.`a_model`='Post'AND`Model`.`a_foreign_key`=186);
# count: 0
SELECTcount(*) AS`count`FROM`Model`AS`Model`WHERE (`Model`.`deleted_at` IS NULLAND`Model`.`a_model`='Post'AND`Model`.`a_foreign_key`=186) GROUP BY`Model`.`user_id`;
# count: ''
If there are values to group up, everything works as expected, but if not, MySQL returns an empty string instead of a 0 (zero).
@cusspvz What result do you expect - a count for each group, or the number of groups?
Honestly i din't quite remember, but after checking our internal issue related with this and the image it had, i think it is the number of users with entries with the polymorphed model.
Problem was on mysql returning an empty string instead of zero, you can check that behavior with mysql-client.
Activity
BridgeAR commentedon May 17, 2015
@cusspvz Would you be so kind and check if your issue still persists and if, if my linked fix fixes the issue?
janmeier commentedon May 24, 2015
@cusspvz What result do you expect - a count for each group, or the number of groups?
Asuming:
Do you want
Or 2, the number of groups (which is guess is equal to
COUNT DISTINCT user_id)cusspvz commentedon May 26, 2015
@BridgeAR
Think your PR fixes this issue.
@janmeier
Honestly i din't quite remember, but after checking our internal issue related with this and the image it had, i think it is the number of users with entries with the polymorphed model.
Problem was on
mysqlreturning an empty string instead of zero, you can check that behavior withmysql-client.