I have a join table (foos_bars) which used to just be a join table in a HABTM relationship. Now I want to create a FooBars model to hold extra attributes about the relationship without losing any of the data in the table, however I can''t think of a way to add the promary key column without an error. How do I do it? 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 -~----------~----~----~----~------~----~------~--~---
doesn''t rails add an id column anyway? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A HABTM association doesn''t use an id primary key in the table definition. The structure is similar to: table ''table1_table2'' t.column table1_id, :integer t.column table2_id, :integer Since you''re now stating you want the join to be pushed to a separate model now, with attributes; you''ll change both model definitions to have has_many :myNewJoinyThing. The model will also have the same association. Since it is a separate model you can add attributes as well. Gareth Adams wrote:> I have a join table (foos_bars) which used to just be a join table in a HABTM > relationship. > > Now I want to create a FooBars model to hold extra attributes about the > relationship without losing any of the data in the table, however I can''t think > of a way to add the promary key column without an error. How do I do it? > > 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 -~----------~----~----~----~------~----~------~--~---
Gareth Adams wrote:> I have a join table (foos_bars) which used to just be a join table in a > HABTM relationship. > > Now I want to create a FooBars model to hold extra attributes about the > relationship without losing any of the data in the table, however I > can''t think > of a way to add the promary key column without an error. How do I do it?Turning a join table into a full-fledged join model requires a few changes: 1) Rename the table from foos_bars to fubars, or whatever is compatible with your model name. 2) Add an ''id'' field for the primary key, auto-increment int 3) Fix all the associations that used habtm to use has_many :through. I''ve heard reports that doing step 2 using migrations can cause problems. It might be better to create the new join model table and transfer the data from the old table to the new one. -- 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 -~----------~----~----~----~------~----~------~--~---