I'm trying to do bi-directional one-to-one with doctrine.
User model
<?php
/**
* @Entity
* @Table(name="User")
*/
class User {
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/**
* @OneToOne(targetEntity="Cart",mappedBy="user",cascade={"persist"})
*/
public $cart;
}
Cart model
<?php
/**
* @Entity
* @Table(name="Cart")
*/
class Cart {
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/**
* @OneToOne(targetEntity="User",inversedBy="cart")
* @JoinColumn(name="user_id", referencedColumnName="id")
*/
public $user;
}
And I want to set the cart like that
<?php
$user->cart = new Cart;
$entityManager->flush();
The cart has been created, but the user_id
is not set. (NULL)
What's wrong ?
(I've not created getters/setters for test)