Wrong id passed when joining tables

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

On Nov 4, 2006, at 2:46 PM, Ed wrote:

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”

I’m not sure what’s happening specifically, but you should try:

 @players = Player.find(:all,
   :include => :person,
   :order => "people.last_name, people.first_name"


– Tom M., CTO
– Engine Y., Ruby on Rails Hosting
– Reliability, Ease of Use, Scalability
– (866) 518-YARD (9273)