问题
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