Hey list, Any easy way to do a has_one, belongs_to based off a key that is NOT the ID field? I am working with a legacy table that has a grouping column in the table, I need to have a has_one association off this grouping column. Otherwise, I guess I''ll just have to make a method, which isn''t a big deal. Regards Mikel --~--~---------~--~----~------------~-------~--~----~ 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 Feb 6, 2008 5:41 PM, Mikel Lindsaar <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Any easy way to do a has_one, belongs_to based off a key that is NOT > the ID field? > > I am working with a legacy table that has a grouping column in the > table, I need to have a has_one association off this grouping column. > > Otherwise, I guess I''ll just have to make a method, which isn''t a big deal.Both has_one and belongs_to accept a :foreign_key parameter. http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M001104 http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M001105 -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
On Feb 13, 2008 9:20 AM, Greg Donald <gdonald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 6, 2008 5:41 PM, Mikel Lindsaar <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Any easy way to do a has_one, belongs_to based off a key that is NOT > > the ID field? > > > > I am working with a legacy table that has a grouping column in the > > table, I need to have a has_one association off this grouping column. > > > > Otherwise, I guess I''ll just have to make a method, which isn''t a big deal. > > Both has_one and belongs_to accept a :foreign_key parameter.No, I know that, but the foreign_key param expects the source record''s ID value to be in the ID column. What I am talking about is a self referrential table where a person might have several records in the table, but these records are grouped by a grouping value, like an entity id column. So each record has it''s own unique ID, but many records could share the grouping ID, no one record is the "parent", as each record in the group belongs to each other. But maybe I''ll check out the self-refferential stuff again, I might have missed something obvious. Mikel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---