开发者

Fetch all rows that column_id is in the array of id's, then order by id

开发者 https://www.devze.com 2023-02-23 15:01 出处:网络
I am trying this, not sure if I am doing this correctly: U开发者_如何学Goser.where(\"region_id => ?\", region_ids).order(\"id ASC\")

I am trying this, not sure if I am doing this correctly:

U开发者_如何学Goser.where("region_id => ?", region_ids).order("id ASC")

region_ids = [1234,234322,234324,2343,....]

Also, will this work if the region_ids is empty (not null, but empty)

I am seeing an error:

check the manual that corresponds to your MySQL server version for the right syntax to use near '=> NULL) ORDER BY id ASC' at line 1:

When I was in debugger mode, I output the region_ids and it was [].


You're mixing up Ruby and SQL syntax within the string. What you want is more like ("region_id in (?)", region_ids) or ({ "region_id" => region_ids }).


You need to reverse the order of the two lines, region_ids should be set before the User.where becuase the way it is now region_ids is NULL when you call where().

0

精彩评论

暂无评论...
验证码 换一张
取 消