chore: add support for scope relationship to all models

This commit is contained in:
Randall Morey committed 2020-07-15 12:41:58 -04:00
1 parent 20361ef00c
commit 5a438c7bc9
3 files changed
+40 -1

No files matched your search

+10
View File
@@ -1,7 +1,17 @@
import Model from '@ember-data/model';
import { belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
export default class BaseModel extends Model {
// =relationships
/**
* Scope of this resource, if any.
* @type {ScopeModel}
*/
@belongsTo('scope', {async: false, inverse: false}) scope;
// =attributes
/**
+1 -1
View File
@@ -24,7 +24,7 @@ export default class ScopeModel extends GeneratedScopeModel {
*/
@hasMany('scope', {inverse: 'parentScope'}) childrenScopes;
// =computed
// =attributes
/**
* @type {boolean}
+29
View File
@@ -11,6 +11,35 @@ module('Unit | Model | base', function (hooks) {
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) {
assert.expect(3);
const store = this.owner.lookup('service:store');