RAILS:复杂的查找条件
假设我们有这样的模型:
触发器 属于 :position
位置 has_many :trigger
Position 有一些字段,包括 :posx、:poxy,也许还有一些我们想要过滤的其他字段......
本质上。在触发器控制器中,我想找到属于 posx 和 posy 某个范围内的所有触发器。
我已经在 cakephp 的一个查询中完成了这一点,所以我知道它应该是可能的,但我不知道如何在 Rails 中构建它。此外,我不知道如何做“和”和“或”等...
谢谢!
Let us say we have models as such:
Trigger
belongs_to :position
Position
has_many :trigger
Position has a few fields including :posx, :poxy, and maybe few other fields we would like to filter by...
Essentially. Within the triggers_controller, I would like to find all triggers that fall within some range of posx and posy.
I've done this in one query in cakephp so I know it should be possible, but I don't know how to structure this in rails. Furthermore, I don't know how to do "and" and "or" etc...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将创建一个范围来处理这种潜在的常见查找:
然后在您的控制器中您只需执行以下操作:
I would create a scope to handle this sort of potentially common lookup:
Then in your controller you would just do: