How do you scope ActiveRecord associations in Rails 3?

后端 未结 6 1691
你的背包
你的背包 2021-01-30 01:21

I have a Rails 3 project. With Rails 3 came Arel and the ability to reuse one scope to build another. I am wondering if there is a way to use scopes when defining a relationsh

6条回答
  •  滥情空心
    2021-01-30 02:07

    I use something like:

    class Invoice < ActiveRecord::Base
      scope :aged_0,  lambda{ where("created_at IS NULL OR created_at < ?", Date.today + 30.days).joins(:owner) }
    end 
    

提交回复
热议问题