-
Full error message:
I currently have two tables:
and
A user record can initially be created before setting the gender, and I want to make sure I don't get any errors and instead return null if trying to load the gender ( My user model is set up with the relation like so: class User extends BaseModel {
@column({isPrimary: true})
public id: number;
@column()
public genderId: number;
@belongsTo(() => Gender)
public gender: BelongsTo<typeof Gender>;
} I've tried doing:
but got the same error. Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
set in user migrations to, maybe help table
.integer('gender_id')
.references('id')
.inTable('genders')
.defaultTo(null)
.onDelete('SET NULL') |
Beta Was this translation helpful? Give feedback.
-
I set directly on the model value to null and this work for me :)
|
Beta Was this translation helpful? Give feedback.
set in user migrations to, maybe help