I have two entities: User
and UserInfo
:
class User
{
...
/**
* @ORM\OneToOne(targetEntity="UserInfo")
* @ORM\JoinColumn(name="userinfo_id", referencedColumnName="id_user")
* @Serializer\Groups({"o", "i-self-editUser"})
*/
private $userInfo;
...
}
class UserInfo
{
/**
* @var integer
*
* @ORM\Column(name="id_user", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="users_id_user_seq", allocationSize=1, initialValue=1)
*/
private $idUser;
...
}
And I'm trying to deserialize a User sent by means of JMSSerializer and its Doctrine Contructor. Everything works fine if UserInfo
is not specified. User is loaded from the DB and the fields sent are updated:
By sending:
{
"username": "test@test.us",
"email": "test@test.us",
"name": "test",
"lang": "en-US"
}
What I get deserialized is User's and UserInfo's well loaded.
But if I try to send something like this:
{
"username": "test@test.us",
"email": "test@test.us",
"name": "test",
"lang": "en-US"
"user_info": {
"short_date_format": "Y-m-dd"
}
}
short_date_format
is updated and serialized, but all the other fields will not be loaded from the DB, setting all of them to null
. This is not the behavior I would like to get. How can I fix this?
Update
I thought I'd better patch a single "nesting level" if I want to do it properly. The URL could resemble this (FOSRestbundle controller's annotation):
* @Patch("/users/{username}/userInfo", requirements={"username"=".+(\.)?\w+"})
this way, I can patch userInfo by following Ocramius' piece of suggestion. Can anyone give me some feedback about this? Do you think it could be a good/best practice in order to implement a decent patch?