My user will send something like this to my endpoint:
{
"user": {
"name": "John",
"age": 24,
"address": {
"street": "Another street",
"number": 543
}
}
}
Then, I need to:
- Create a row on user’s table
- Create a row on address’ table
- Return the user with the address nested, basically in the same way above
{
"data": {
"id": 10,
"name": "John",
"age": 24,
"address": {
"id": 45,
"street": "Another street",
"number": 543
}
}
}
Some questions:
-
How is the best way to get this from controller’s params and create the record? Just accessing
params.address
and callingAddress.create_address
? -
How can I get this from the database and return back to the user? In the nested format above