Join table with additional data

Hello everybody!

I need to define a relation between two table, but the join table need some other data and i don’t know how to use the link function.

I explain you

TABLE user

user_id (int)

user_name (varchar)

TABlE item

item_id (int)

item_name (varchar)

TABLE users_items

id

user_id (int)

item_id (int)

number (int)

As you can see, in the join table i need to define some extra fields like number that define more info for the relation.

Now, with link i would define a viaTable to define the hunction table (as explained here) and then use the link() function on the created item to save the relation.

But what can i do here? I think i need to create manually the relation saving all the data in the table with a sql query, but i hope there is a more fast and efficent way…

Any idea?

Thanks

When the junction table has additional columns, I think it would be better to define a dedicated ActiveRecord for it and define 2 sets of relations: a 1-N relation between User and UserItem, and another 1-N relation between Item and UserItem. The linking and unlinking between User and Item will be handled in a very basic manner - creating and deleting UserItem models.

It may sounds very naive and primitive, but I can’t think of a better solution.