lucid icon indicating copy to clipboard operation
lucid copied to clipboard

Lucid does not expect a relationship to be null in a preload.

Open filipebraida opened this issue 3 years ago • 0 comments

Package version

@adonisjs/lucid": "^18.1.0

Node.js and npm version

Node: v16.14.0 NPM: 8.3.1

Sample Code (to reproduce the issue)

Example:

const users = await User.query().preload('profile')

Model:

export default class User extends BaseModel {
  public static selfAssignPrimaryKey = true

  @column({ isPrimary: true })
  public id: BigInt

  @column()
  public profileId: number | null

  @belongsTo(() => Profile)
  public profile: BelongsTo<typeof Profile>

  @hasMany(() => Profile)
  public profiles: HasMany<typeof Profile>

  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime
}

Error:

Uncaught:
Exception: Cannot preload "profile", value of "User.profileId" is undefined

BONUS (a sample repo to reproduce the issue)

https://github.com/filipebraida/lucid-issue

filipebraida avatar Aug 17 '22 04:08 filipebraida