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 %>
<p><%= 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.
<p>119, 119</p>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Nov 4, 2006, at 2:46 PM, Ed wrote:> 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"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 Mornini, CTO -- Engine Yard, Ruby on Rails Hosting -- Reliability, Ease of Use, Scalability -- (866) 518-YARD (9273) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---