Ruby on rails Rails 3将相关模型与之连接';s的默认范围
我尝试使用以下设置跨模型进行查询Ruby on rails Rails 3将相关模型与之连接';s的默认范围,ruby-on-rails,activerecord,arel,Ruby On Rails,Activerecord,Arel,我尝试使用以下设置跨模型进行查询 Class Scorecard < AR::Base default_scope where(:archived => false) belongs_to :user has_many :scorecard_metrics end Class ScorecardMetric < AR::Base belongs_to :scorecard end Class User < AR::Base has_many :sc
Class Scorecard < AR::Base
default_scope where(:archived => false)
belongs_to :user
has_many :scorecard_metrics
end
Class ScorecardMetric < AR::Base
belongs_to :scorecard
end
Class User < AR::Base
has_many :scorecards
end
这对我来说似乎很混乱,有没有办法加入并包含加入的关联的默认范围?看起来我找到了我想要的答案,我就是这么做的
scope :for_user, lambda { |user| joins(:scorecard).where('scorecards.user_id = ?', user.id) & Scorecard.scoped }
如果没有重复的逻辑,这会更好看起来我找到了我想要的答案,我就是这么做的
scope :for_user, lambda { |user| joins(:scorecard).where('scorecards.user_id = ?', user.id) & Scorecard.scoped }
如果没有重复的逻辑,Scorecard.scoped的意思是什么?Scorecard.scoped只是记分卡的默认范围,&执行联合什么是
&记分卡。scoped
的意思是什么?Scorecard.scoped只是记分卡的默认范围,&执行联合