[英]Ember.Js Reflexive Association
I am trying to implement "follower/following" relationship. 我正在尝试实施“追随者/追随者”的关系。
app/templates/users.hbs--------------------------- 应用程序/模板/ users.hbs ---------------------------
{{#each model as |user|}}
...
<button {{action 'follow' user}}>Follow</button>
{{/each}}
app/routes/users.js--------------------------- 应用程序/路由/ users.js ---------------------------
follow(user){
//currentUser is the one clicking on 'follow' button
//and it works.I can successfully alert it's properties.
currentUser.get('followings').pushObject(user);
},
app/models/user.js----------------------- 应用程序/模型/ user.js的-----------------------
...
followings: DS.hasMany('user',{inverse: null}),
followers: DS.hasMany('user',{inverse: null}),
Now, this solution is causing this error below; 现在,此解决方案导致此错误;
Uncaught TypeError: Cannot read the property 'modelName' of undefined at assertPolymorphicType.notifyRecordRelationshipAdded
Try this: 尝试这个:
followings: DS.hasMany('user', { inverse: 'followers' },
followers: DS.hasMany('user', { inverse: 'followings' },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.