Class ModelA < ActiveRecord::Base
has_many :modelb
end
Class ModelB < ActiveRecord::Base
has_many :modelc
end
Class ModelC < ActiveRecord::Base
has_many :modeld
named_scope :due_on, lambda {|date| { :conditions => {:due_date => date}}}
end
Class ModelD
named_scope :has_feature, lambda {|feature| { :conditions => {:feature => feature}}}
end
我可以执行以下操作吗
a = ModelA.find(1)
a.modelb.modelc.due_on(today).modeld.has_feature(somefeature).should return_an_array_of_instances_of_ModelD
如果不是,那么从模型对象引用相关建模对象的最佳实践是什么。