Given a tag
and post
ManyToMany relationship defined as follow:
post.js
import Ember from 'ember';
import Model from 'ember-data/model';
import { hasMany } from 'ember-data/relationships';
export default Model.extend({
tags: hasMany('tag')
}
tag.js
import Ember from 'ember';
import Model from 'ember-data/model';
import { hasMany } from 'ember-data/relationships';
export default Model.extend({
posts: hasMany('post')
}
When adding tags
to post
using pushObject
let aPost = this.store.findRecord('post', 1),
aTag = this.store.findRecord('tag', 1);
aPost.get('tags').pushObject(aTag); // aPost is not commited yet
How to restore aPost.tags
to its initial state?
Aucun commentaire:
Enregistrer un commentaire