Closed q8tywolf closed 4 months ago
20.6.0
I have a user model in adonis and Job model
In the job model I have the following
Migration note this foreign key is nullable ... table.integer('handled_by').nullable().unsigned() .references('id').inTable('users') ...
... table.integer('handled_by').nullable().unsigned() .references('id').inTable('users') ...
Model ... @belongsTo(() => User, { localKey: 'handledBy', foreignKey: 'id' }) declare handlingBy: BelongsTo<typeof User>
...
@belongsTo(() => User, { localKey: 'handledBy', foreignKey: 'id' })
declare handlingBy: BelongsTo<typeof User>
@column({ columnName: "handled_by" }) declare handledBy: number; ... Query
@column({ columnName: "handled_by" })
declare handledBy: number;
await Job.query().where('listedBy', user.id).preload('listingBy').preload('handlingBy')
Error When the handledBy is null, I get the error "status_message": "\"Job.handlingBy\" expects \"handledBy\" to exist on \"User\" model, but is missing",
"status_message": "\"Job.handlingBy\" expects \"handledBy\" to exist on \"User\" model, but is missing",
No response
Fixed I had to make the localKey this key in User with BelongsTo
Package version
20.6.0
Describe the bug
I have a user model in adonis and Job model
In the job model I have the following
Migration note this foreign key is nullable
... table.integer('handled_by').nullable().unsigned() .references('id').inTable('users') ...
Model
...
@belongsTo(() => User, { localKey: 'handledBy', foreignKey: 'id' })
declare handlingBy: BelongsTo<typeof User>
@column({ columnName: "handled_by" })
declare handledBy: number;
...
Queryawait Job.query().where('listedBy', user.id).preload('listingBy').preload('handlingBy')
Error When the handledBy is null, I get the error
"status_message": "\"Job.handlingBy\" expects \"handledBy\" to exist on \"User\" model, but is missing",
Reproduction repo
No response