Asterix wrote:> I''m a total newby to Ruby and jumped into an application that
quickly
> went over my head. My question relates to how I can setup the models in my
> app so that I can reference the same database table using different names.
> Here''s how my database is setup:
>
> table requests
> id
> title
> sponsor_id
> initiator_id
> implementor_id
>
> table employees
> id
> fname
> lname
>
> The sponsor_id, initiator_id, and implementor_id fields are all intended
> to reference an row in the employees table. I''m confused as to
how I make
> rails understand that these foreign keys all reference the same table.
> Can anyone help?
belongs_to :sponsor, :class_name => "Employee", :foreign_key =>
"sponsor_id"
belongs_to :initiator, :class_name => "Employee", :foreign_key
=>
"initiator_id"
belongs_to :implementor, :class_name => "Employee", :foreign_key
=>
"implementor_id"
You should read the docs on belongs_to. It''s all right there.
--
Josh Susser
http://blog.hasmanythrough.com
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---