-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cascade unloading #1
Comments
I suggest switching to decorators and then relying on the // app/models/human.js
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany, belongsTo } from 'ember-data/relationships';
import { cascadeDelete, cascadeUnload } from 'ember-data-cascade-delete';
export default Model.extend({
name: attr('string'),
@cascadeUnload
@cascadeDelete
heart: belongsTo('heart', { async: true, inverse: 'human' }),
@cascadeUnload
@cascadeDelete
legs: hasMany('leg', { async: true, inverse: 'human' })
}); |
Using the above pattern, you could even walk the extra mile and make sure that when a relationship is cleared, the orphaned child record gets deleted / unloaded. |
For the record, 2 years after, I now think that this shouldn't be a decorator, but an option of belongsTo/hasMany like it always was. Here is how it looks nowadays: // app/models/human.js
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
export default class Human extends Model {
@attr('string')
name;
@belongsTo('heart', { async: true, inverse: 'human', cascadeDelete: true })
heart;
@hasMany('leg', { async: true, inverse: 'human', cascadeDelete: true })
legs;
} The reason is that this is still describing a relationship. Cascade unloading is still desirable and it would be nice if we could not use mixins. |
If I unload a
Human
I would expect itsLeg
s to be unloaded as well, since they cannot exist without their correspondingHuman
.This isn't currently possible by only using an
Adapter
mixin. Do you have some alternative ideas?The text was updated successfully, but these errors were encountered: