pass parameter from controller to models condition
- by Alex
I'm trying to bind a param to a join via a named scope., but I'm getting an error.
What is the correct way to do that?
has_one :has_voted, :class_name => 'Vote', :conditions => ['ip = :userIp']
# named scopes
scope :with_vote, lambda {|ip| {
:include => [:has_voted],
# like this ??
:conditions => [:has_voted => {:conditions => {:userIp => ip}} ]
}}
Idea.with_vote(request.ip).all
I believe I need the condition definition in the model for it to appear in the ON clause of a JOIN, rather then in the WHERE one.
Edit I'm trying to get the following query
select Ideas.*, Votes.* from Ideas
left outer join Votes
on Votes.Idea_id = Idea.id AND Votes.ip = {request.ip}