What is the equivalent of the has_many 'conditions' option in Rails 4?
ruby-on-rails-4
Solution
Needs to be the second arg:
class Customer < ActiveRecord::Base
has_many :orders, -> { where processed: true }
end
http://edgeguides.rubyonrails.org/association_basics.html#scopes-for-has-many
RESPONSE TO UPDATE:
Put the order inside the block:
has_many :friends, -> { where(friendship: {status: 'accepted'}).order('first_name DESC') }, :through => :friendships
Problem
Can someone tell me what is the equivalent way to do the following line in Rails 4? ``` has_many :friends, :through => :friendships, :conditions => "status = 'accepted'", :order => :first_name ``` I tried the following: ``` has_many :friends, -> { where status: 'accepted' }, :through => :friendships , :order => :first_name ``` But I get the following error: ``` Invalid mix of scope block and deprecated finder options on ActiveRecord association: User.has_many :friends ```