ruby on rails - MySQL COUNT results getting interpreted in RoR as a string instead of as an integer -
Here's my query for inquisitors: Only the first and last lines should be placed on this question:
As the item count as SELECT s.parent_id ID, COUNT (s.parent_id), I add it to the upper part (SELECT item_id, user_id, MAX (Created_at) created from item_views iv WHERE iv .user_id =? Item_id by GROUP) vii But as v.item_id, VITTIIIIIIIIIEIIIII = I.category_id Join INNER, Parent.title as parent_title, parent.id as parent_id from categories AS node, Parents WHERE as node.lft categories parent.lft and parent.rgt) s on s.node_id = I.category_id where (i.updated_at> v .created_at or v.created_at is an IS tap) and i.updated_at & gt; ? S.parent_id by group; When I call it using find_by_sql
, the values under the counts
column are string like " 1 "
instead of integers, of course, I can easily call to_i
, but of course this is not the best solution. I suspect that there may be something wrong with my query This is due to mysql returning string.
You need to enter your returned calculation attribute in the form of an integer.
find_by_sql
returns an array of properties from your query, the railing considers those attributes as a string, and since counting is your specialty query array, it returns a Take a look at the documentation of the method to confirm that the string is:
Comments
Post a Comment