Folks, What is the convention for primary key fields in joining tables in RoR? I have a model representing a joining table, and I can''t seem to prevent ActiveRecord''s find method from looking for an id column. I don''t have an auto-incremented field in my table (happy to add one if that is the convention), and therefore my primary key is the combination of the 2 foreign keys. Thanks, Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Short answer: You can''t have multi-column prikeys. Rails assumes single column primary keys. By having a multi-column prikey, you''re breaking that basic assumption, and you''ll have to do all sorts of non-standard magic in order to get it to work. Sorta like multi-databases (although much worse).>From DHH himself:http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/140320 Chris Hughes wrote:> Folks, > > What is the convention for primary key fields in joining tables in RoR? > > I have a model representing a joining table, and I can''t seem to > prevent ActiveRecord''s find method from looking for an id column. I > don''t have an auto-incremented field in my table (happy to add one if > that is the convention), and therefore my primary key is the > combination of the 2 foreign keys. > > Thanks, > Chris--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
eden li wrote:> Short answer: You can''t have multi-column prikeys.If it''s good enough for DHH, it''s good enough for me. :) Thanks! Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---