获取column_id在id数组中的所有行,然后按id排序
我正在尝试这个,不确定我是否正确执行此操作:
User.where("region_id => ?", region_ids).order("id ASC")
region_ids = [1234,234322,234324,2343,....]
另外,如果region_ids为空(不是空,而是空),这会起作用吗
我看到一个错误:
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:
当我处于调试器模式时,我输出region_ids及其曾是 []。
I am trying this, not sure if I am doing this correctly:
User.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 [].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在字符串中混合了 Ruby 和 SQL 语法。您想要的更像是
("region_id in (?)", Region_ids)
或({ "region_id" => Region_ids })
。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 })
.您需要颠倒两行的顺序,region_ids 应设置在 User.where 之前
因为现在当你调用 where() 时,region_ids 是 NULL。
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().