Open rlabrovi opened 11 months ago
I have noticed that in network tab when creating new item it's sending options as empty array, but if I console.log actions new before paylod the data is there:
Do you mean options
is empty in Network
tab but before
hook of new
action has got options
in the request.payload
? This should be impossible since the payload contains whatever had been sent from the frontend
@dziraf Exactly that. I also thought that is impossible but here is video.
https://github.com/SoftwareBrothers/adminjs/assets/3057962/de4b4794-5f83-4912-85c2-f124fe534e18
In the video you're showing a Response
(not Request
) which only means that options
are not returned from the server. So my guess is that they're actually sent from the frontend but Mongo is unable to process the flattened payload.
You could try to modify your before
hook to unflatten it:
import { flat } from 'adminjs';
const unflattenPayload = (request) => {
if (request.method === 'get') return request;
const { payload = {} } = request;
const newPayload = flat.unflatten(payload);
request.payload = newPayload;
return request;
}
@dziraf Thanks for reply. I tried with unflattening payload, now it's creating options property but without any values in it:
https://github.com/SoftwareBrothers/adminjs/assets/3057962/4e47c1cc-23b1-4afe-a4dc-c7f141c2aae5
Any ides what else can I do?
This function could be messing up the payload: https://github.com/SoftwareBrothers/adminjs-mongoose/blob/master/src/resource.ts#L181
I'm not sure why it's even needed for Mongoose though. Could you try to modify this function in your:
node_modules/@adminjs/mongoose/lib/resource.js
by adding console.log
s to see where your payload disappears? It's still odd because:
const parsedParams = { ...params }
makes a copy of your payload so in worst case scenario it should persist it with parsing.
Contact Details
No response
What happened?
I'm trying to save nested object but data I provide is not saving to database. I'm using adminjs v6.7.5
I have noticed that in network tab when creating new item it's sending options as empty array, but if I console.log actions new before paylod the data is there:
Bug prevalence
When creating new resource
AdminJS dependencies version
What browsers do you see the problem on?
Firefox
Relevant log output
No response
Relevant code that's giving you issues
No response