I’ve been struggling all day with this. Read a ton of documentation, tried several different ways and still no luck. Hope someone can help me out. I’m using REST adapter & serializer.
The problem is I cannot persist models that reference each other:
At the end of my second day googling I found this post:
Here’s what it says about saving hasMany relationships:
Note though that, by default, RESTSerializer, will not add DS.hasMany
associated IDs to the objects that it serializes, since those
associations are specified on the “many” side (i.e., those which have a DS.belongsTo association). So, in our example, although a Post has many comments, those IDs will not be added to the Post object
This is totally unintuitive. Not only it is not documented anywhere, there is no clear solution either. Should I update the “many” side in the backend and refresh the record afterwards? What they suggest is using the DS.EmbeddedRecordsMixin which will serialize hasMany relationships by default. 2 days wasted on such a trivial thing. Is it just me constantly hitting the wall with Ember Data?
That will serialize records when sending them to your backend and deserialize them as IDs.
2 days wasted on such a trivial thing. Is it just me constantly
hitting the wall with Ember Data?
ED has its rough parts, but there have been a lot of improvements recently, and the team is working on it. The API to extend it and make it suit your API needs is excellent… the documentation can be a little better, I agree.