plugin-axios
plugin-axios copied to clipboard
Mapping multiple entities from one response
How do I map multiple entities types from a single response? Say for instance I hit a user_with_tasks endpoint which returns me a user but all their tasks also. What would I use to map to both models. I found some code somewhere that shows I would use "dataTransformer" and then inside use
data.tasks.map((task) => {
Object.assign(task);
Object.assign(task.attributes);
});
does this look right? I might be completely misunderstanding.
Yeah I was on the wrong track although the above assign operation is important in my context the active ingredient, to map to multiple models, is simply the relationship settings if that is setup the mapping to multiple models is automatic <3