Closed waffleau closed 2 years ago
Hello 👋
Usually, the issue lies with the data type mis-match in the database. As I can see the id
column in categories
and the topics
table is an integer and the FK inside the pivot table are bigInt
https://github.com/waffleau/adonis-lucid-preload-bug/blob/master/database/migrations/1663380305927_topics_categories.ts#L9-L10
Thanks @thetutlage, can confirm this was indeed the issue 🙈. Preload is working as expected now in both my toy repo and my main project. Appreciate your help!
Hello 👋
Usually, the issue lies with the data type mis-match in the database. As I can see the
id
column incategories
and thetopics
table is an integer and the FK inside the pivot table arebigInt
https://github.com/waffleau/adonis-lucid-preload-bug/blob/master/database/migrations/1663380305927_topics_categories.ts#L9-L10
But why not throw an error, even without a warning? I have been debugging whole night, finally find the answer here. 😅
Package version
@adonisjs/core
:5.8.6
,@adonisjs/lucid
:18.1.1
Node.js and npm version
node
:16.15.0
npm
:8.5.5
yarn
: 1.22.19Sample Code (to reproduce the issue)
Preload is not working through a many-to-many relationship. I'm using Postgres and haven't tested any other databases.
I've defined two simple models joined through a pivot table (using
bigInteger
for column type):If I try to load categories through
Topic.query().preload('categories')
the returned category lists are always empty. If I retrieve a single topic and usetopic.load('categories')
they are loaded as expected.Bug is reproduced in a test case in the linked repo. Also included a test case to show that it works with
load
. To reproduce just pull down the repo, set up.env
and runnode ace test
.BONUS (a sample repo to reproduce the issue)
https://github.com/waffleau/adonis-lucid-preload-bug