plugin-axios icon indicating copy to clipboard operation
plugin-axios copied to clipboard

Mapping multiple entities from one response

Open ivan006 opened this issue 3 years ago • 1 comments

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.

ivan006 avatar Jan 18 '23 12:01 ivan006

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

ivan006 avatar Jan 23 '23 11:01 ivan006