Rule | 🏷️ | ✨ |
---|---|---|
no-invalid-relationships |
🏆 | ✅ |
Tip
A partial/complete autofix for this rule is possible but has not been implemented. An autofix PR would be a welcome addition.
Note
Ensures relationship configuration is setup appropriately
This rule ensures that the async
and inverse
properties are specified in @belongsTo
and @hasMany
decorators in EmberData models.
This rule disallows:
- Using
@belongsTo
without specifying theasync
andinverse
properties. - Using
@hasMany
without specifying theasync
andinverse
properties.
async
may be eithertrue
orfalse
, the historical default when unspecified wastrue
inverse
may be either the name of the field on the model on the other side of the relationship ornull
- See the relationships guide for more information on valid configurations
Examples of incorrect code for this rule:
import Model, { belongsTo, hasMany } from '@ember-data/model';
export default class FolderModel extends Model {
@hasMany('folder', { inverse: 'parent' }) children;
@belongsTo('folder', { inverse: 'children' }) parent;
}
Examples of correct code for this rule:
import Model, { belongsTo, hasMany } from '@ember-data/model';
export default class FolderModel extends Model {
@hasMany('folder', { async: true, inverse: 'parent' }) children;
@belongsTo('folder', { async: true, inverse: 'children' }) parent;
}