Ember data: embedded records without ids ready to go

Coding

From quite a year I’m mainly working with Ember. Recently, due to recent changes on ember data about embedded records i thought it could fit my needs.

But after a bit of digging, i’ve easily found that embedded records do still want an id key to be present to work. As of my API, i have repeated data structure in different API calls, so i wanted to share the capability of a model in many context. Embedded models were great but unfortunately the problem to have an id made me unable to use them… as they are.

Digging i’ve found that modifying indeed ember-data to do what i wanted was really easy: a mixin that properly configured can make ember-data models get the id automatically client side.

Here is the code I’ve ended up with. I started from embedded record mixin and modified its behavior to support noKey option in attrs structure.

This is an example in how to use it. With this post and maybe some merge request on github i’ll try to make ember-data people aware of the problem and maybe evaluate this solution.

Looks like I’m not alone in this problem. Here is a list of documents i’ve read/tried before writing my own mixin. Of course none of them worked in my case  but led me the way to the code i wrote.

 

Ember data serializer that normalizes embedded records without ids

Jsfiddle demo

Serializing Embedded Relationships with Ember Data 1.0.0 beta

How to make embedded hasMany relationship work with ember-data

 

Previous
Mastering Extjs: all you need to know if you work with Extjs daily

Leave a Reply

%d bloggers like this: