有时不正确的关系不正确 [英] Inverse relations not showing correctly sometimes

查看:197
本文介绍了有时不正确的关系不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模型,问题和用户。

I have two models, Issues and Users.

问题有两个属性属于用户,所有者和创建者。

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

当问题/ index.hbs模板呈现问题时,一些所有者和创建者是正确的,但是其他人丢失,即使以前显示相同的显示。例如,创建者Jhon(id 4)出现在某些问题中,但不在其他问题上,具有相同的创建者:4

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

在Chrome中使用Ember检查器,

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

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:



Json:

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

我在做错什么?

谢谢,

推荐答案

我认为这是因为你在第2个字段中属于用户以及属于问题的用户2字段。 Ember不能决定谁是谁。尝试从问题中删除反向选项,并从用户中删除owner_user和creator_user,并查看它是否正常工作。

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.

这篇关于有时不正确的关系不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆