You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running into a problem when trying to use model.relation('relation').sync([1, 2]) when the relationship is defined as many-to-many and has an onQuery. This is because when using relation Lucid doesn't doesn't load the data in the "relation" table, it only loads the pivot table.
It looks like you are using onQuery, as of now the documentation is probably not teaching us mush about this but what i have concluded is that onQuery will run for any types of request that is made on your Model User
onQuery should be used on specific type of request that need preloading your Role model.
I tried a small fix on your code and it looks like ok.
Running into a problem when trying to use
model.relation('relation').sync([1, 2])
when the relationship is defined as many-to-many and has anonQuery
. This is because when usingrelation
Lucid doesn't doesn't load the data in the "relation" table, it only loads the pivot table.Given these two models (and a join table):
This will cause an error:
The error:
This is because the
roles
table isn't joined when callingmodel.relation(...)
.Package version
Lucid v18.4.2
Node.js and npm version
node v18.7.0
npm v8.15.0
Sample Code (to reproduce the issue)
https://github.com/waffleau/adonis-many-to-many-bug
npm install
npm test
The text was updated successfully, but these errors were encountered: