user3240928
user3240928

Reputation: 555

Ruby Change Join ON fields

I have a query that i run run Ruby and i am trying to change what fields that the 2 tables are joining ON

I want to have to do a query like this:

Select * from Teamplayers join Liveplayers On Nid = Live_Player_id

What have in Ruby right now is:

Teamplayer.joins(:liveplayer).where(:teamid => 1).all

This out puts the query of

Select * from Teamplayers join Live_players on Live_players.id = Teamplayer.live_player_id

My problem is that id and live_player_id are not the 2 fields that should be matching, it should by Nid(from live_players) and live_player_id(from teamplayers)

can someone help me with this? Is it a relation thing or a bad query?

Upvotes: 1

Views: 78

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54882

You can specify the join like the following:

Teamplayer.joins('LEFT JOIN Live_players ON Live_players.Nid = Teamplayers.live_player_id')

But your table names are confusing me, I don't know if I used the proper names/case ...

Upvotes: 1

Related Questions