I have boxes and balls. Balls are in boxes. Ball can be either red and green.
class Box < ActiveRecord::Base
has_many :balls
end
class Ball < ActiveRecord::Base
belongs_to :box
scope :green, where(:color => "green")
end
I want to set has_many only with green balls. I know that finder_sql method exists, but i don't know how to set via scopes.
I want that following examples to be equivalent:
@orders = @box.balls
@orders = @box.balls.green