diff --git a/test/orm/base-model.spec.ts b/test/orm/base-model.spec.ts index 688741b2..4eff4383 100644 --- a/test/orm/base-model.spec.ts +++ b/test/orm/base-model.spec.ts @@ -6389,6 +6389,55 @@ test.group('Base model | inheritance', (group) => { assert.isFalse(MyBaseModel.$relationsDefinitions.has('emails')) }) + test('overwrite relationship during relationsip', async (assert) => { + class SocialProfile extends BaseModel { + @column() + public socialParentId: number + + @column() + public userId: number + } + + class Profile extends BaseModel { + @column() + public userId: number + } + + class Email extends BaseModel { + @column() + public userId: number + } + + SocialProfile.boot() + Profile.boot() + Email.boot() + + class MyBaseModel extends BaseModel { + @column() + public id: number + + @hasOne(() => Profile) + public profile: HasOne + } + + class User extends MyBaseModel { + @hasMany(() => Email) + public emails: HasMany + + @hasOne(() => SocialProfile, { foreignKey: 'socialParentId' }) + public declare profile: HasOne + } + + MyBaseModel.boot() + User.boot() + + assert.deepEqual(User.$getRelation('profile').relatedModel(), SocialProfile) + assert.deepEqual(User.$getRelation('profile').model, User) + + assert.deepEqual(MyBaseModel.$getRelation('profile').relatedModel(), Profile) + assert.deepEqual(MyBaseModel.$getRelation('profile').model, MyBaseModel) + }) + test('allow overwriting relationships', async (assert) => { class Profile extends BaseModel { @column()