Adding fields to intermediary table

Hey guys,

So, I have a many_to_many relationship for pages and users. I then have a page_users lookup table. Now, it seemed to me that it would be a great opportunity to put a users page permissions on the lookup table, so the lookup has an additional integer field. However, it’s not quite so simple as that. I can’t use this without a primary key, and I can’t figure out how to have a composite primary key. If I specify no primary key, I can’t access the role and with an id key, I can no longer update a relationship or add a relationship without getting:

** (RuntimeError) you are attempting to change relation :users of
 MyApp.Page, but there is missing data.

 If you are attempting to update an existing entry, please make sure
 you include the entry primary key (ID) alongside the data.

 If you have a relationship with many children, at least the same N
 children must be given on update. By default it is not possible to
 orphan embed nor associated records, attempting to do so results in
 this error message.

 It is possible to change this behaviour by setting `:on_replace` when
 defining the relation. See `Ecto.Changeset`'s section on related data
 for more info.

Is there a solution to this? Are there any examples anywhere?

Thanks,
Lee

I thought about it some and realised I’m being stupid. By adding a field to the lookup table, I’ve removed the many to many and created a one_to_one to one_to_one, so I will just start treating it as a hierarchy instead.

Thanks, though :slight_smile:
Lee

1 Like

That would be my suggestion, yeah. :slight_smile: