开发者

Named Scope Extensions - Calling Method Outside Do Block

I have the following named_scope in my User model:

  named_scope :all_stars, :joins => [:all_stars] do
    def overall
      se开发者_C百科lf.find(:all, :conditions => ['recordable_type = ?', 'User'])
    end
  end

I want to do this:

  named_scope :all_stars, :joins => [:all_stars] do
    def overall
      overall_all_stars_condition
    end
  end

  def overall_all_stars_condition
    self.find(:all, :conditions => ['recordable_type = ?', 'User']) 
  end

Can it be done?


If you can make the other thing into another named scope, you can then chain together the two scopes, which will get you what you want.

named_scope :all_stars, :joins => [:all_stars]
named_scope :overall, :conditions => ['recordable_type = ?', 'User']

Then you should be able to call it as such:

object.all_stars.overall.all
object.overall.all_stars.find(:all)
# etc

And also create a method that does the same thing:

def overall_all_stars_condition
  self.all_stars.overall.all
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜