Active Record Question

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?

Christian K. 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 S.
http://blog.hasmanythrough.com

Josh S. 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.