# EmbeddedRecordsMixin: Embedded hasMany is only visible after explicitly calling store.find()

**URL:** <https://discuss.emberjs.com/t/embeddedrecordsmixin-embedded-hasmany-is-only-visible-after-explicitly-calling-store-find/12744>\
**Category:** Ember Data\
**Created:** [April 8, 2017, 3:15pm UTC](https://discuss.emberjs.com/t/embeddedrecordsmixin-embedded-hasmany-is-only-visible-after-explicitly-calling-store-find/12744 "2017-04-08T15:15:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hummingbird](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@Hummingbird](https://discuss.emberjs.com/u/Hummingbird)\
**Post date:** [April 8, 2017, 3:15pm UTC](https://discuss.emberjs.com/t/embeddedrecordsmixin-embedded-hasmany-is-only-visible-after-explicitly-calling-store-find/12744/1 "2017-04-08T15:15:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hummingbird](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@Hummingbird](https://discuss.emberjs.com/u/Hummingbird)\
**Post date:** [April 10, 2017, 5:53pm UTC](https://discuss.emberjs.com/t/embeddedrecordsmixin-embedded-hasmany-is-only-visible-after-explicitly-calling-store-find/12744/2 "2017-04-10T17:53:48Z")

</div>

So, after some more debugging, I think I found the cause: The hasMany relationship does not return the records directly, but an EachProxy which seems to works like a promise. Therefore I need to wait for the promise on the post to be resolved `post.get('comments').then(() => { ... })` before doing anything with the comments.
