Updating already existing event with relationship when a booking is saved in Ember Updating already existing event with relationship when a booking is saved in Ember node.js node.js

Updating already existing event with relationship when a booking is saved in Ember


The question is quiet old but let me give an answer anyways as it's highly upvoted.

Ember Data does not serialize the has-many site of one-to-many relationships by default in update requests. This could be customized by overriding shouldSerializeHasMany method of the responsible serializer.

Please be aware that Ember Data does not serialize the many-part of one-to-many relationships by default cause that is likely to cause race conditions and conflicts. Imagine two users A and B are fetching the current relationships from backend at the same time. A adds a new related record. A little bit later B adds another related record by replacing the existing relationships with a new list adding one resource. As B is not aware of the record added by A it will be silently removed. B overrides the change of A.

JSON:API specification supports relationship links to address these issue even for many-to-many and many-to-none relationships. But for many-to-one only updating one-side is the easiest solution.


Maybe I understand the question wrongly but is there a point in actually saving the event with all the bookings ?

I mean usually for a one to many relationship like this one, the bookings will have an eventId pointing to the event they are related to but the event doesn't hold a reference to the bookings. Saving changes on an event should automatically be reflected on all the bookings referencing it.