Closed arnoldtkl closed 2 years ago
Nice! Thanks for the PR! I made a similar hook at feathers-utils called setData
a while ago.
I don't know if I would expect setField
to throw an error on arrays or that it just works as you intended in your PR.
Reasons for throwing an error:
as: 'data.user_id'
is basically wrong. It should be more like: as: 'data[].user_id'
or something.as: 'data[].entries[].user_id'
or something similar?What do you think @arnoldtkl? Clearly we cannot leave setField
to ignore multi:true
at all but should we maybe add a new setData
that is more declarative than setField
?
Thanks for the quick reply! I agree with you, setData
is more straightforward and declarative. Maybe we can make a note at the setField
documentation, e.g when dealing in multi:true
service , the result may not work as expected, we will recommend check on setData
......
By the way, I will close this pull request. Because my code didn't cover nested arrays and not handling well in the as
field format.
Very good point to add it to the docs. Would you be up to add a PR for that? Any help is highly appreciated.
Ok, sure. But, the setData not yet included in this library. I will write a note about handling multi:true
may not work as expected.
To handle the use case where
multi:true
,create
method, the data is in array format. E.g Inside hookWhen POST array of data, currently the merge result will become
Expected result: