Ember.js belongsTo中需要双重定义,并且有许多带有固定装置的?

Ember.js belongsTo中需要双重定义,并且有许多带有固定装置的?,ember.js,ember-data,Ember.js,Ember Data,我正在测试一个非常简单的模型关系。在切换到真正的后端之前,我正在使用Fixture适配器。在某种程度上遵循和,我发现我需要在每个装置中定义关系的两侧 这是对Fixture适配器的限制,还是后端/数据库也必须同时存储这两个方面(这对于SQL之类的东西来说是非标准的) 型号: // app/models/comment.js ... export default DS.Model.extend({ text: DS.attr('string'), author: DS.attr('strin

我正在测试一个非常简单的模型关系。在切换到真正的后端之前,我正在使用Fixture适配器。在某种程度上遵循和,我发现我需要在每个装置中定义关系的两侧

这是对Fixture适配器的限制,还是后端/数据库也必须同时存储这两个方面(这对于SQL之类的东西来说是非标准的)

型号:

// app/models/comment.js
...
export default DS.Model.extend({
  text: DS.attr('string'),
  author: DS.attr('string'),
  //post: DS.belongsTo('post', {async: true})  // async only needed on one side - true??
  post: DS.belongsTo('post')
}).reopenClass({
FIXTURES: [
    {
      id: 1,
      text: 'Text of the comment goes right in here',
      author: 'Fred',
      post: 1
    },
    {
      id: 2,
      text: 'TWO 2222 comment two here',
      author: 'Barney',
      post: 1
    },
    {
      id: 3,
      text: 'third comment here',
      author: 'Wilma',
      post: 2
    },
...

// app/models/post.js
...
export default DS.Model.extend({
  text: DS.attr('string'),
  comments: DS.hasMany('comment', {async: true})
}).reopenClass({
    FIXTURES: [
    {
      id: 1,
      text: 'Post ONE - Lorem ipsum dolor sit amet, consectetur risus.',
      comments: [1,2]  // Why is this required??
    },
    {
      id: 2,
      text: 'Post TWO - consectetur adipiscing elit. Sed gravida faucibus risus.',
      comments: [3,4]  // Why is this required?
    },
...
我的余烬信息:

  • 灰烬检查员1.8.2
  • 余烬1.12.0
  • 余烬数据1.0.0-beta.18
  • jQuery 1.11.3

这是对固定装置的限制


我建议使用而不是fixture-然后您可以开始使用将在生产中使用的Serialiser/适配器,并且对代码的工作方式更加自信。

谢谢@jmurphyau-很酷的插件,我来看看。我实际上在想我现在可以把我的样本连接到后端了。或者现在切换到使用“generate resource”命令连接后端和前端设置的模式。另一个选项是,通过使用假装器。