Idea: Deep creation of nested objects #358
torgeros
started this conversation in
Feature request
Replies: 3 comments
-
For good measure, this is what an undocumented, unvalidated endpoint for this looks as an endpoint-extension: module.exports = async (req, res, manifest) => {
const { name, email, attendance, guests } = req.body;
//TODO validate everything
let guestIds = [];
for (const g in guests) {
g = await manifest.from("guests").create(g);
guestIds.push(g.id);
}
const newRegistration = await manifest.from("registrations").create({
name: name,
email: email,
attendance: attendance,
guestIds: guestIds,
});
res.json({ newRegistration });
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
@torgeros good point, I have to see how each DB manages cascades on create/update to see what are the expected behaviors |
Beta Was this translation helpful? Give feedback.
0 replies
-
Cascade deletions also were asked on Discord |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Disclaimer: This is just an idea, not an active request!
It would be very helpful to be able to create nested objects in one go.
An example would be a reservation system with named guests:
current state of GET
When getting the registration, you can already use
.with(['guests'])
to include the guests.And you will get this object:
current state of POST
When creating the registration, you need to:
In a worst-case, if any of these fail their validation, you would need to delete the created entries now.
target feature for POSTing
create everything in go:
And because I cannot emphasize this enough:
The most important part of this is the validation.
It would not be a huge burden to, on top of the CRUD base, implement this as an endpoint manually.
BUT, that would also mean that every field in these objects needs to be manually validated (required, isEmail, ...).
Beta Was this translation helpful? Give feedback.
All reactions