Hello everyone! I’m dealing with this problem and I cannot find a nice solution. I’ve a model with a hasMany relationship. When I create them I want to send in the same request the related models that also will be created. But I query them, I need the relationship to be serialized as an array with ids.
Let’s see an example. We have two models like the folllowing
You will have to extend a serializer and modify methods like normalizeQueryResponse and serialize. If you could provide what your JSON response looks like that could help.
Hi @injaon! As David rightly pointed out, there are two parts to consider:
Posting a mouth. If you want to post tooth entities alongside mouth you probably will have to use something like EmbeddedRecordsMixin and/or extend serialize in MouthSerializer.
Retrieving a mouth: It totally depends on what your API returns. You can transform the server response overriding the MouthSerializer’s normalizeFindRecordResponse to return what you need.
I’d probably have 2 models here: mouth and tooth. A mouth hasMany() tooth. Use JSONSerializer since your GET response looks like it fits that format already. Then, create a mouth serializer, and override the serialize method to adjust the POST format.