Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneToOne entities are not deserialized if passing a nested one-to-one property #652

Closed
bertuz opened this issue Sep 26, 2016 · 1 comment

Comments

@bertuz
Copy link

bertuz commented Sep 26, 2016

I have 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 sent fields are updated:

By sending:

{
    "username": "[email protected]",
    "email": "[email protected]",
    "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": "[email protected]",
    "email": "[email protected]",
    "name": "test",
    "lang": "en-US"
    "user_info": {
        "short_date_format": "Y-m-dd"
    }
}   

short_date_format is update, 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. Am I misusing JMSSerializer and the doctrine constructor?

@goetas
Copy link
Collaborator

goetas commented Sep 27, 2016

this is because the serializer places a new object as "user_info", if you want to update it, you have to provide a way to load your object using one of https://github.com/schmittjoh/serializer/tree/master/src/JMS/Serializer/Construction strategies

@goetas goetas closed this as completed Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants