chore: add support for scope relationship to all models
This commit is contained in:
3 files changed
+40
-1
No files matched your search
@@ -1,7 +1,17 @@
|
|||||||
import Model from '@ember-data/model';
|
import Model from '@ember-data/model';
|
||||||
|
import { belongsTo } from '@ember-data/model';
|
||||||
import { computed } from '@ember/object';
|
import { computed } from '@ember/object';
|
||||||
|
|
||||||
export default class BaseModel extends Model {
|
export default class BaseModel extends Model {
|
||||||
|
|
||||||
|
// =relationships
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope of this resource, if any.
|
||||||
|
* @type {ScopeModel}
|
||||||
|
*/
|
||||||
|
@belongsTo('scope', {async: false, inverse: false}) scope;
|
||||||
|
|
||||||
// =attributes
|
// =attributes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export default class ScopeModel extends GeneratedScopeModel {
|
|||||||
*/
|
*/
|
||||||
@hasMany('scope', {inverse: 'parentScope'}) childrenScopes;
|
@hasMany('scope', {inverse: 'parentScope'}) childrenScopes;
|
||||||
|
|
||||||
// =computed
|
// =attributes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
|||||||
@@ -11,6 +11,35 @@ module('Unit | Model | base', function (hooks) {
|
|||||||
assert.ok(model);
|
assert.ok(model);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('it may have a scope relationship', function (assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
const store = this.owner.lookup('service:store');
|
||||||
|
store.push({
|
||||||
|
data: {
|
||||||
|
id: 'o_1',
|
||||||
|
type: 'scope'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
store.push({
|
||||||
|
data: {
|
||||||
|
id: '123abc',
|
||||||
|
type: 'project',
|
||||||
|
attributes: {},
|
||||||
|
relationships: {
|
||||||
|
scope: {
|
||||||
|
data: {
|
||||||
|
id: 'o_1',
|
||||||
|
type: 'scope'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const scope = store.peekRecord('scope', 'o_1');
|
||||||
|
const model = store.peekRecord('project', '123abc');
|
||||||
|
assert.equal(model.scope, scope);
|
||||||
|
});
|
||||||
|
|
||||||
test('it has a displayName attribute', function (assert) {
|
test('it has a displayName attribute', function (assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
const store = this.owner.lookup('service:store');
|
const store = this.owner.lookup('service:store');
|
||||||
|
|||||||
Reference in new issue
Block a user