【问题标题】:ember-pouch: does not load hasMany relationship when the belongsTo side is polymorphicember-pouch:当 belongsTo 端为多态时不加载 hasMany 关系
【发布时间】:2017-05-25 18:22:34
【问题描述】:

我有一个使用 ember-pouch 适配器进行本地和远程存储的 ember-data 应用程序。

belongsTo 端是多态时,我无法加载hasMany 关系。我在hasMany 一侧使用了async: true/falsedonstsave: true/false 选项,但无济于事。

设置:

  • post 可以有多个comments
  • comment 可以有多个comments
  • comment 属于 commentable
// app/models/post.js
import DS from 'ember-data';
import { Model } from 'ember-pouch';

export default Model.extend({
    DS.hasMany('comment', { inverse: 'commentable' });
});

// app/models/comment.js
import DS from 'ember-data';
import { Model } from 'ember-pouch';

export default Model.extend({
    DS.belongsTo('commentable', { polymorphic: true });
    DS.hasMany('comment', { inverse: 'commentable' });
});

问题

调用post.get('comments') 不会加载任何内容。但是,如果 cmets 被单独加载到 store 中,那么post 能够正确渲染 cmets:

// In the console (being mindful that `post.get('comments')` returns a promise)

const post = store.findRecord('post', '123');
post.get('comments').get('length'); // => 0

store.findAll('comment');
post.get('comments').get('length'); // => 12

【问题讨论】:

  • 你有解决办法吗?
  • 我没有。不久之后,我提交了该项目,但从未解决。我很想听听你是否知道。

标签: ember.js ember-data couchdb pouchdb relational-pouch


【解决方案1】:

在实验期间对我有用的东西(尽管我在适配器中大量修改了 ember-pouch)是使用 post.get('comments').content.length 但不要问我为什么会这样以及是否应该这样......

编辑: 问题似乎是当时没有加载数据。所以可能像post.get('comments').then(function() {this.debug(post.get('comments').length})) 这样的东西会起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多