Inverse relations not showing correctly sometimes

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 14:25:19

问题


I have two models, Issues and Users.

Issues have two properties that belongs to User, owner and creator.

When the issues/index.hbs template renders the issues, some owner and creator are correct, but others are missing, even when they are the same displayed before. For example, the creator Jhon (id 4) appears in some Issues but not in other issues, that have the same creator:4

Using the Ember inspector in Chrome, those users are correctly loaded, so they are there.

Issue model:

import DS from 'ember-data';

export default DS.Model.extend({
  title: DS.attr('string'),
  ...,
  owner: DS.belongsTo('user', { inverse: 'owner_user',async:true }),
  creator: DS.belongsTo('user', { inverse: 'creator_user',async:true })
});

User model:

import DS from 'ember-data';

export default DS.Model.extend({
  full_name: DS.attr('string'),
  owner_user: DS.belongsTo('issue',{ inverse: 'owner',async:true}),
  creator_user: DS.belongsTo('issue',{ inverse: 'creator',async:true})
});

Template:

{{issue.creator.given_name}}
{{issue.owner.given_name}}

Json:

issues: [
{
id: 5,
title: "xxxxxxxxxxxxxxxxxxx",
messages: [11,25],
creator: 100,
owner: 249
},
{...},{...}]

What I'm doing wrong?

thanks,


回答1:


I think it is because you have in issue 2 fields that belongs to user and in user 2 fields that belongs to issue. Ember can't decide who is who. Try to remove inverse options from issue and remove owner_user and creator_user from user and see if it will work.



来源:https://stackoverflow.com/questions/31992024/inverse-relations-not-showing-correctly-sometimes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!