hey! I have the following table structure in my DB | users | ------------ | (pk)id | | username | | pass | ------------ (1:n) | users_objects | | objectattributes | ------------------ ---------------------------------- | (fk,pk)user_id | (1:n) | (pk)attribute | |(fk,pk)object_id| | (pk,fk) users_objects_user_id | | .... | |(pk,fk) users_objects_object_id | ------------------ | value | ---------------------------------- (1:n) | objects | ------------- | (pk)id | | ... | | ... | ------------- So basically i have a many to many relation (with attributes) between users and objects and a 1 to many relation between users_objects and objectattributes. I have introduced models for user, objects and users_objects. The many to many realtion is modeled with the :through associaction. How does the relation between users_objects and objectattributes in ActiveRecord look like? -- 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 -~----------~----~----~----~------~----~------~--~---
Christian Kerth wrote:> I have the following table structure in my DB > > | users | > ------------ > | (pk)id | > | username | > | pass | > ------------ > > (1:n) > > | users_objects | | objectattributes | > ------------------ ---------------------------------- > | (fk,pk)user_id | (1:n) | (pk)attribute | > |(fk,pk)object_id| | (pk,fk) users_objects_user_id | > | .... | |(pk,fk) users_objects_object_id | > ------------------ | value | > ---------------------------------- > (1:n) > > | objects | > ------------- > | (pk)id | > | ... | > | ... | > ------------- > > So basically i have a many to many relation (with attributes) between > users and objects and a 1 to many relation between users_objects and > objectattributes. > > I have introduced models for user, objects and users_objects. The many > to many realtion is modeled with the :through associaction. > > How does the relation between users_objects and objectattributes in > ActiveRecord look like?ActiveRecord doesn''t understand composite primary keys. You''ll have to create an (pd)id field in users_objects. (You''ll need that anyway if you''re using has_many :through.) Then objectattributes can use that as the fk for users_objects_id. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Josh Susser wrote:> ActiveRecord doesn''t understand composite primary keys. You''ll have to > create an (pd)id field in users_objects. (You''ll need that anyway if > you''re using has_many :through.) Then objectattributes can use that as > the fk for users_objects_id.I have installed the composite_keys extension for active record. Now it seems to work with composite keys as expected. -- 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 -~----------~----~----~----~------~----~------~--~---