所以我想说我有两种模式:用户和预订。
用户
var User = DS.Model.extend({
name: DS.attr('string'),
books: DS.hasMany('book')
});
图书
var Book = DS.Model.extend({
title: DS.attr('string'),
users: DS.hasMany('user')
})
所以我希望能够“结账”并为某个用户归还书籍。鉴于以下 BookController ,最新的做法是删除和添加关系而不实际删除该书?
var BookController = Ember.ObjectController.extend({
needs: ['userProfile'],
actions: {
checkOutBook: function(){
var currentBook = this.get('model');
var userBooks = this.get('controllers.userProfile.model.books');
//add relationship to user
},
returnBook: function() {
var currentBook = this.get('model');
var userBooks = this.get('controllers.userProfile.model.books');
//remove relationship to user
}
}
})
使用Ember 1.5.1
和Ember-Data 1.0.0-beta.8.2a68c63a
答案 0 :(得分:0)
//add
userBooks.pushObject(currentBook);
//remove
userBooks.removeObject(currentBook)