Mitchell Gould
2008-Jul-02 22:41 UTC
belongs_to, has_many relationship using other foreign key
I am creating a relationship between two tables and objects. public_user has_many :orders orders belongs_to :public_user however I need to connect them using a foreign key other than the public_user_id. Namely the customer_number field. How do I code this in Ruby on Rails? Thank you for your time in advance. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2008-Jul-02 22:44 UTC
Re: belongs_to, has_many relationship using other foreign key
> I am creating a relationship between two tables and objects. > > > public_user > has_many :orders > > orders > > belongs_to :public_user > > however I need to connect them using a foreign key other than the > public_user_id. Namely the customer_number field. > > > How do I code this in Ruby on Rails?Look into the :foreign_key option to has_many/belongs_to. It allows you to change the field used to join on. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mitchell Gould
2008-Jul-03 00:54 UTC
Re: belongs_to, has_many relationship using other foreign k
Philip Hallstrom wrote:>> however I need to connect them using a foreign key other than the >> public_user_id. Namely the customer_number field. >> >> >> How do I code this in Ruby on Rails? > > Look into the :foreign_key option to has_many/belongs_to. It allows > you to change the field used to join on. > > -philipThank a lot Philip I will check that route now. Cheers, Mitch -- 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?hl=en -~----------~----~----~----~------~----~------~--~---