我正在使用Ember和Firebase。我想更新两个用户的朋友'执行操作时列出。模型的工作方式是每个用户都属于friendsList。每个friendsList都有很多朋友(都是用户)。但是,当我运行此代码时,我收到错误:
currentFriendsList.save is not a function
为什么会发生这种情况?
以下是代码:
var userId = this.controllerFor('teams/new').get('userId');
let currentUser = this.get('user').get('currentUser');
let myUser = this.get('store').peekRecord('user', currentUser.id);
let actorName = myUser.get('name');
if (userId != null){
let selectedUser = this.get('store').peekRecord('user', userId);
let selectedFriendsList = selectedUser.get('friendsList');
let currentFriendsList = myUser.get('friendsList');
selectedFriendsList.get('friends').pushObject(myUser);
currentFriendsList.get('friends').pushObject(selectedUser);
currentFriendsList.save().then(() =>
selectedFriendsList.save());
以下是friendslist模型:
user: DS.belongsTo('user', { inverse: 'friendsList' }),
friends: DS.hasMany('user')
以下是用户模型的适用部分:
friendsList: DS.belongsTo('friendslist', { inverse: 'user' })