Christopher J. Bottaro
2007-Aug-30 23:34 UTC
belongs_to with foreign keys that reference non primary key columns
Hello, I have a situation where the foreign key into a table doesn''t correspond to that table''s primary key: my_table ------------- id (pk) name ... other_table -------------- id (pk) my_table_name (fk references my_table(name)) ... I want to be able to say something like: class OtherTable < ActiveRecord::Base belongs_to :my_table, :foreign_key => { :my_table_name => :name } end OtherTable.find(:first).my_table Is this possible? If not, what is the reasoning behind the decision? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christopher J. Bottaro
2007-Sep-12 18:33 UTC
Re: belongs_to with foreign keys that reference non primary key columns
On Aug 30, 6:34 pm, "Christopher J. Bottaro" <cjbott...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > I have a situation where the foreign key into a table doesn''t > correspond to that table''s primary key: > > my_table > ------------- > id (pk) > name > ... > > other_table > -------------- > id (pk) > my_table_name (fk references my_table(name)) > ... > > I want to be able to say something like: > class OtherTable < ActiveRecord::Base > belongs_to :my_table, :foreign_key => { :my_table_name => :name } > end > > OtherTable.find(:first).my_table > > Is this possible? If not, what is the reasoning behind the decision? > > Thanks.Is this possible? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---