I need to combine name scope with or operator... Something like:
class Product < ActiveRecord::Base
belongs_to :client
scope :name_a, where("products.name = 'a'")
scope :client_b, joins(:client).where("clients.name = 'b'")
scope :name_a_or_b, name_a.or(client_b)
end
Thx
For Rails 3:
Heres a hack I would use to deal with that missing feature:
From Arel documentation
This RailsCast shows you how to use the
.or
operator. However, it works with Arel objects while you have instances ofActiveRecord::Relation
. You can convert a relation to Arel usingProduct.name_a.arel
, but now you have to figure out how to merge the conditions.