What is the equivalent of the has_many 'conditions' option in Rails 4?

后端 未结 5 1236
渐次进展
渐次进展 2020-12-02 12:11

Can someone tell me what is the equivalent way to do the following line in Rails 4?

has_many :friends, :through => :friendships, :conditions => \"statu         


        
5条回答
  •  臣服心动
    2020-12-02 12:24

    In order to work on Rails 4.1 (my case), i had to put:

    has_many :friends, -> { where(friendships: { status: 'accepted' }) }, through: :friendships
    

    Note the S on friendships. It refers directly to the database name.

提交回复
热议问题