First, the stack trace provided by the API in the response body can help us understand the problem :
In the console, we can find the SQL request executed. Let's take the easier example, with the empty addresses list. We get the following line :
As we can see, the API is trying to set the field user_id (in the table user_address) to null.
By looking into the database structure, we can find that $addresses is the only field of the User entity which has a one to many relationship (meaning each User have multiple UserAddress, and each UserAddress have one User) :
The error is not due to the fact that the link is stored in the user_address table, because the link between user_mails_phones and the users is stored in the table user_mails_phones. Here is the schema representing the model the user_address model.
Description
By passing the following body to route
PATCH /users/{id}
:We get an error 500 (Internal Server Error).
If we pass anything else, as long as the body does not contain the entry
addresses
:The return code is 200.
Even if we pass an empty list to
addresses
:The return code is 500
Investigation
First, the stack trace provided by the API in the response body can help us understand the problem :
In the console, we can find the SQL request executed. Let's take the easier example, with the empty
addresses
list. We get the following line : As we can see, the API is trying to set the fielduser_id
(in the tableuser_address
) to null.By looking into the database structure, we can find that
$addresses
is the only field of theUser
entity which has a one to many relationship (meaning eachUser
have multipleUserAddress
, and eachUserAddress
have oneUser
) :The error is not due to the fact that the link is stored in the
user_address
table, because the link betweenuser_mails_phones
and theusers
is stored in the tableuser_mails_phones
. Here is the schema representing the model theuser_address
model.