I do have a comment model, which has an 1-n relationship to reply. Replies are always retrieved embedded in the same response - therefore I am using the EmbeddedRecordsMixin:
model/comment.js:
export default DS.Model.extend({
replies: DS.hasMany('reply'),
post: DS.belongsTo('post', { inverse: 'replies'}),
replyCount: Ember.computed('replies.[]', function() {
return this.get('reply.length');
})
})
model/reply.js:
export default DS.Model.extend({
comment: DS.belongsTo('comment', { inverse: 'replies'}),
});
serializer/comment.js:
export default Serializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
replies: {
embedded: 'always'
}
}
})
this all has been working really well, until I started to make use of computed properties within the comment model. If the comment is directly loaded from the store via this.get('store').findRecord('comment', id)
, the computed property for the reply count is correct (no matter if findRecord triggers an actual request to the server or not). However, if the comment is accessed via a reference on the parent model (a post, mapped via belongsTo and hasMany) the replies are an array of length 0. If I have a look in the ember inspector, the replies are shown as <computed>
. If I click on that, it resolves into <(unknown mixin):ember...>
, retriggers the computed property and has the reply array correctly initialised with all data (no request to the server is being made). If I call findRecord on the comment after it has been loaded and shows the empty replies, the returned record is correctly initialised (without a request to the server).
model/post.js:
export default DS.Model.extend({
replies: DS.hasMany('reply')
})
Has anyone ever seen anything similar and does have an idea what to check? I have been through everything twice and can not find any reasonable explanation why this is happening.