Skip to content

Ember-addon which adds behaviour to DS.Model so belongsTo relationships are also rolled back.

License

Notifications You must be signed in to change notification settings

dylanmensaert/ember-rollback-relationships

Repository files navigation

ember-rollback-relationships

ember install ember-rollback-relationships

Adds behaviour to DS.Model so belongsTo and hasMany relationships can also be rolled back.

Notes

Don't forget to call model.rollbackAttributes() yourself if required.

Calling this._super(); is mandatory if you are using any of the following Events:

  • ready
  • didCreate
  • didLoad
  • didUpdate

Many-to-many relationships are not supported!

API

rollbackRelationships(kind)

Performs a rollback on the current model for every relationship that meets the given criteria.

kind String belongsTo and hasMany

// app/models/blog.js
export default DS.Model.extend({
  user: DS.belongsTo()
});

// app/models/post.js
export default DS.Model.extend({
  user: DS.belongsTo()
});

// app/models/user.js
export default DS.Model.extend({
  blogs: DS.hasMany(),
  posts: DS.hasMany()
});

// Rollback blogs and posts (all relationships)
user.rollbackRelationships();

// Rollback user (all belongsTo relationships)
blog.rollbackRelationships('belongsTo');

// Rollback blogs and posts (all hasMany relationships)
user.rollbackRelationships('hasMany');

rollbackRelationship(name)

Performs a rollback on the current model for the given relationship only.

name String of the relationship

// app/models/blog.js
export default DS.Model.extend({
  user: DS.belongsTo()
});

// app/models/post.js
export default DS.Model.extend({
  user: DS.belongsTo()
});

// app/models/user.js
export default DS.Model.extend({
  blogs: DS.hasMany(),
  posts: DS.hasMany()
});

// Rollback user only
blog.rollbackRelationship('user');

// Rollback blogs only
user.rollbackRelationship('blogs');

About

Ember-addon which adds behaviour to DS.Model so belongsTo relationships are also rolled back.

Resources

License

Stars

Watchers

Forks

Packages

No packages published