Serialize to JSON including all relationships and their attributes using new JSON-API Serializer


#1

Hi.

I have implemented a JSON-API backend and I’m using ember (1.13.4) and ember data (1.13.5) to pull my data in to the store. All is working well and the store is populated with all of the models and their attributes/relationships.

However, I need to serialize my models to JSON in order to pass them to an external library (datatables.net) and have them displayed in a table. When I do the serialization I see all of my attributes and relationships but the relationships are not embedded so I don’t see any of the relationship’s attributes. Instead I just get an id and type within each relationship.

Is there an easy way of telling the serializer that I want all of the relationships to be embedded (or included in JSON-API parlance) or do I have to do it manually by modifying the “serialize”, “serializeBelongsTo” or “serializeHasMany” hooks?

Any guidance would be appreciated.

Thanks.


#2

Did you try http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html { embedded: 'always' } as far as I understand this it should do what you want. Perhaps you can also ask the maintainer of https://github.com/kjhangiani/ember-cli-jquery-datatables


#3

Hi.

Thanks for your reply. I did try the embedded records mixin as I had used it successfully in my previous non-JSON-API API but it seems to change the format of the serailzed object to one not compatible with JSON-API. This is OK for populating a datatables table but not for generating a payload to send to the backend. I was concerned that this would affect push requests to my JSON-API backend as when the model being saved was serialized the format would be incompatible.

Thanks.