Multiple belongsToMany relationships on the same entity #1384
-
Using Adonis 4.1, I have a mutual belongsToMany relationship between "mocs" (basically posts) and "tags". This works great. Now I want to set up another belongsToMany relationship between mocs and collections. The first issue I ran into was The workaround I found for this was to assign a different column name so I do this in the migration file:
instead of this:
...awkward, but the migration succeeded. But I'm getting errors with sync: attach: Is this a bug, or am I missing something somewhere? In my Moc model I have:
And in the Collection model I have:
any help is appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You have to define the custom key name in your relationship declaration as well. Docs does cover it https://adonisjs.com/docs/4.1/relationships#_belongs_to_many |
Beta Was this translation helpful? Give feedback.
-
Follow up question... but when collections are bulk inserted using any advice? |
Beta Was this translation helpful? Give feedback.
You have to define the custom key name in your relationship declaration as well. Docs does cover it https://adonisjs.com/docs/4.1/relationships#_belongs_to_many