Skip to content

Commit

Permalink
test: add test for overwriting relationship during inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
Harminder Virk authored and Harminder Virk committed Oct 25, 2021
1 parent 40a8090 commit 768dc87
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/orm/base-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Profile>
}

class User extends MyBaseModel {
@hasMany(() => Email)
public emails: HasMany<typeof Email>

@hasOne(() => SocialProfile, { foreignKey: 'socialParentId' })
public declare profile: HasOne<typeof SocialProfile>
}

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()
Expand Down

0 comments on commit 768dc87

Please sign in to comment.