I have an ember-data app that uses the ember-pouch adapter for local & remote storage.
I am unable to load hasMany
relationships when the belongsTo
side is polymorphic. I've played with async: true/false
and donstsave: true/false
options on the hasMany
side, to no avail.
The setup:
post
can have manycomments
.comment
can have manycomments
.comment
belongs tocommentable
.
// 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' });
});
The Problem
Calling post.get('comments')
loads nothing. If comments are loaded into the store separately, however, then post
is able to correctly render comments:
// 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
Aucun commentaire:
Enregistrer un commentaire