Skip to content

Commit

Permalink
Add failing test for related virtualAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
venables committed Mar 26, 2019
1 parent 6e1d82e commit bc4d11e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/unit/model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,59 @@ describe('Model', () => {
});
});

it('should include virtualAttributes for related models', () => {
class Model1 extends modelClass('Model1') {
static get virtualAttributes() {
return ['foo'];
}

get foo() {
return 'foo';
}
}

class Model2 extends modelClass('Model2') {
static get virtualAttributes() {
return ['bar'];
}

static get relationMappings() {
return {
model1: {
relation: Model.BelongsToOneRelation,
modelClass: Model1,
join: {
from: 'Model2.model1Id',
to: 'Model1.id'
}
}
};
}

get bar() {
return 'bar';
}
}

let model2 = Model2.fromJson({
a: 'a',
model1: {
b: 'b',
c: 'c'
}
});

expect(model2.toJSON()).to.eql({
a: 'a',
bar: 'bar',
model1: {
b: 'b',
c: 'c',
foo: 'foo'
}
});
});

it('should include methods', () => {
class Model1 extends Model {
foo() {
Expand Down

0 comments on commit bc4d11e

Please sign in to comment.