Skip to content

Commit

Permalink
test: fix breaking inheritance tests
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 c24e33d commit 40a8090
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions test/orm/base-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6355,50 +6355,63 @@ test.group('Base model | inheritance', (group) => {
})

test('inherting a model should copy relationships', async (assert) => {
class Profile extends BaseModel {}
class Email extends BaseModel {}
class Profile extends BaseModel {
@column()
public userId: number
}
class Email extends BaseModel {
@column()
public userId: number
}

Profile.boot()
Email.boot()

class MyBaseModel extends BaseModel {
@column()
public id: number

@hasOne(() => Profile)
public profile: HasOne<typeof Profile>
}

class User extends MyBaseModel {
@column()
public id: number

@hasMany(() => Email)
public emails: HasMany<typeof Email>
}

Profile.boot()
Email.boot()
MyBaseModel.boot()
User.boot()

assert.isTrue(User.$relationsDefinitions.has('emails'))
assert.isTrue(User.$relationsDefinitions.has('profile'))
assert.isTrue(MyBaseModel.$relationsDefinitions.has('profile'))
assert.isFalse(MyBaseModel.$relationsDefinitions.has('emails'))
assert.deepEqual(
MyBaseModel.$relationsDefinitions.get('profile'),
User.$relationsDefinitions.get('profile')
)
})

test('allow overwriting relationships', async (assert) => {
class Profile extends BaseModel {}
class Email extends BaseModel {}
class Profile extends BaseModel {
@column()
public userId: number
}

class Email extends BaseModel {
@column()
public userId: number
}

Profile.boot()
Email.boot()

class MyBaseModel extends BaseModel {
@column()
public id: number

@hasOne(() => Profile)
public profile: HasOne<typeof Profile>
}

class User extends MyBaseModel {
@column()
public id: number

@hasOne(() => Profile, {
onQuery() {},
})
Expand All @@ -6408,8 +6421,6 @@ test.group('Base model | inheritance', (group) => {
public emails: HasMany<typeof Email>
}

Profile.boot()
Email.boot()
MyBaseModel.boot()
User.boot()

Expand Down

0 comments on commit 40a8090

Please sign in to comment.