ruby-on-rails – 帮助加入Rails 3
发布时间:2020-12-17 01:48:48 所属栏目:百科 来源:网络整理
导读:我有以下型号: class Event ActiveRecord::Base has_many :action_itemsendclass ActionItem ActiveRecord::Base belongs_to :event belongs_to :action_item_typeendclass ActionItemType ActiveRecord::Base has_many :action_itemsend 我想要做的是,对于
我有以下型号:
class Event < ActiveRecord::Base has_many :action_items end class ActionItem < ActiveRecord::Base belongs_to :event belongs_to :action_item_type end class ActionItemType < ActiveRecord::Base has_many :action_items end 我想要做的是,对于给定的事件,找到具有名称为“foo”的动作项类型的所有动作项(例如).所以我认为SQL会像这样: SELECT * FROM action_items a INNER JOIN action_item_types t ON a.action_item_type_id = t.id WHERE a.event_id = 1 AND t.name = "foo" 任何人都可以帮我翻译成一个很好的活动记录查询吗? (Rails 3 – Arel) 谢谢! 解决方法
好吧,我想我自己解决了.这就是我做的
e = Event.find(1) e.action_items.joins(:action_item_type).where("action_item_types.name = ?","foo") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容