On 11 Jul 2009, at 17:55, Rick wrote:

>
> On Sat, Jul 11, 2009 at 12:30 PM, Frederick
> Cheung<[email protected]> wrote:
>
>>> Now I want to retrieve the team_id for the (opponent) inside the
>>> schedules table.  Each team plays approx. 12 opponents.  So, I would
>>> like to use an each statement to retrieve that bit of data at the  
>>> same
>>> time I'm iterating through my table view...
>>>
>>
>> Why not put the team_id for the opponent in the schedules table ?
>>
>> Fred
>
> It's possibly I'm hijacking this thread a bit because I'm still a
> Rails noob, but couldn't opponent by of type Team in another
> belongs_to relationship on schedule? Or is that a bad idea? If so, can
> someone tell me how you'd model that? From an OO perspective you'd
> have
>
> Team team;
> Team opponent;
>
> would you just set up another belongs_to like:
>
> belongs_to :opponent, :class_name => "Team", :foreign_key =>  
> "opponent_id"

That's what I would do (except that the :foreign_key is redundant  
here: rails will default to #{association_name}_id for a belongs_to )

Fred
>
> >


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to