Topic: Passing variables to a has_many condition
The following code is pretty straight forward:
has_many :styles belongs_to :category def self.filter_by_params( params ) self.scoped.includes( :styles => [ :votes ] ).joins( :category ) end
What I'd like to do is pass a condition to :votes, that pulls only votes associated to a user_id. I'd like to pull all styles regardless of the votes, which is why I'm using includes. Is this possible? I know I can use a proc in has_many :conditions but is there a way to pass a variable to that proc? Is it efficient? Is there a better way to go about this, such as writing custom sql?