如何将 find 与关联模型和条件一起使用
我在资源模型和 ResourceType 模型之间有一个 have_and_belong_to_many 关系。
我试图查找由 ResourceType 加入的所有资源,其中 :name 不等于“event”。
我让它工作,这样我就可以找到 ResourceType.names 等于“event”的资源,如下所示:
Resource.find(:all, :order => 'created_at DESC', :include => :resource_types, :conditions => {:resource_types => {:name => 'event'}})
但我想找到带有 :name != 'event' 的其他所有内容。
感谢您的帮助!
I have a have_and_belong_to_many relationship between a Resources model and ResourceType model.
I am trying to find all resources that are joined by a ResourceType with the :name NOT equal to "event".
I have it working so that I can find Resources with ResourceType.names equal to "event" like this:
Resource.find(:all, :order => 'created_at DESC', :include => :resource_types, :conditions => {:resource_types => {:name => 'event'}})
but I want to find everything else with :name != 'event'.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)