mysql - Inner join in ruby on rails 4 -
mysql - Inner join in ruby on rails 4 -
i encountered "undefined method 'join'" error when seek display clubnames current user requested.
in controller:
@clubs = club.find(:conditions=> ["request.userid = session[:userid]"], :joins=>[:request])
in view: @clubs.each |c| c.clubname end
equivalent query wish load
select clubname clubs inner bring together request on request.clubid = clubs.clubid request.userid = session[:userid]
been modifying code various sources doesnt seem working... sources have been trying out are: railsforum , dsone don't seem work in code.
one way you're looking be:
@clubs.joins(:request).where(request: { userid: session[:userid] })
update: doesn't seem working op, because @vee pointed out, table singular. if that's case, it'll need bit less pretty:
@clubs.joins('request').where('request.user_id = ?', session[:userid])
mysql sql ruby-on-rails ruby join
Comments
Post a Comment