I have two tables, people and players. When I do a find on Player and
join people, the wrong id is being returned for my player object.
Here is an example.
Models:
class Person < ActiveRecord::Base
has_one :player
end
class Player < ActiveRecord::Base
belongs_to :person
end
Controller:
@players = Player.find(:all,
:joins => “join people on players.person_id = people.id”,
:order => “people.last_name, people.first_name”
)
View:
<% for player in @players %>
<%= player.id =>, <%= player.person_id => <%end%>
Here is one of the entries in the players table.
mysql> select * from players where person_id=119;
±----±----------±-------+
| id | person_id | active |
±----±----------±-------+
| 116 | 119 | 1 |
±----±----------±-------+
When I render my view, both id and person_id are returning the
person_id.
119, 119