# Model data hooks

**URL:** <https://discuss.emberjs.com/t/model-data-hooks/14141>\
**Category:** Ember Data\
**Created:** [January 17, 2018, 12:28pm UTC](https://discuss.emberjs.com/t/model-data-hooks/14141 "2018-01-17T12:28:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimek](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kimek/32/13608_2.png) [@kimek](https://discuss.emberjs.com/u/kimek)\
**Post date:** [January 17, 2018, 12:28pm UTC](https://discuss.emberjs.com/t/model-data-hooks/14141/1 "2018-01-17T12:28:05Z")

</div>

Hi Chaps, Is there any hooks for ‘model data state’ (afterSerialize) ? I know that we have Adapters and Serializers however I couldn’t find any hooks in docs. I am not able to use afterModel hook as this is only for ‘plain’ model. I’m using JSONAPI

Much appreciate for any help.

Thanks in advance

Regards Matt K.

---

<div class="post-metadata">

**Author:** ![l\_tonz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/l_tonz/32/12634_2.png) [@l\_tonz](https://discuss.emberjs.com/u/l_tonz)\
**Post date:** [January 17, 2018, 4:39pm UTC](https://discuss.emberjs.com/t/model-data-hooks/14141/2 "2018-01-17T16:39:37Z")

</div>

What is your usecase? There are hooks in the route and component. For before rendering and after rendering.

---

<div class="post-metadata">

**Author:** ![kimek](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kimek/32/13608_2.png) [@kimek](https://discuss.emberjs.com/u/kimek)\
**Post date:** [January 17, 2018, 4:49pm UTC](https://discuss.emberjs.com/t/model-data-hooks/14141/3 "2018-01-17T16:49:11Z")

</div>

I have 7 models where the main model is visitor and the rest models are used on specific situations like on click → get data for news model.

I prefer to load only visitor model, load css, components, wait for rendering and after that load data for specific model.

This specific data needs to be formatted and set as default questions to visitor.task(which is relationship to model task).answers (attribute for task).

Case: Clicking on task loading data which needs to be formated and save to attribute answers in model task and task have relationship to visitor. There can be more then 1 task.

If that make sense

---

<div class="post-metadata">

**Author:** ![l\_tonz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/l_tonz/32/12634_2.png) [@l\_tonz](https://discuss.emberjs.com/u/l_tonz)\
**Post date:** [January 17, 2018, 6:01pm UTC](https://discuss.emberjs.com/t/model-data-hooks/14141/4 "2018-01-17T18:01:09Z")

</div>

Hi Kimek,

I’m not too clear on the requirements. But maybe you can load the data upfront and use logic in the templates to render the data depending on the logic.

```auto
//template
{{#if someConditionInController}}
  {{formatted-data-component someData=passedFromController}}
{{else}}
  {{some-other-format-data-component someData=passedFromController}}
{{/if}}

//component

export default Ember.component.extend({

  someData: ''

  formatData(){
    //let changedData = {};
    this.get('someData', changedData);
  }
})

```

Best, Elton

---

<div class="post-metadata">

**Author:** ![kimek](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kimek/32/13608_2.png) [@kimek](https://discuss.emberjs.com/u/kimek)\
**Post date:** [January 18, 2018, 1:35pm UTC](https://discuss.emberjs.com/t/model-data-hooks/14141/5 "2018-01-18T13:35:31Z")

</div>

Hi @l_tonz,

This sounds pretty good and it will work.

I’ve never though to use component as a ‘transformer’.

Thanks a lot !

Have a great day/night 😉
