I am trying to create a bidirectional One-To-Many relation in Doctrine 2.1. I Compared my code to the manual and to other examples but still can't see what I am doing wrong. I only get a blank screen so it's hard to debug. (log_threshold = 4 but no error in the log).
I have those two tables:
user
id
name
cart
id
items
And here are my two models (in short):
/**
* @Entity
* @Table(name="user")
*/
class User
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @OneToMany(targetEntity="Cart", mappedBy="user_id")
*/
private $carts;
}
/**
* @Entity
* @Table(name="cart")
*/
class Cart
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ManyToOne(targetEntity="User", inversedBy="carts")
*/
private $user;
}
Then I try to link them
$user = $this->em->find('models\User', 8);
$cart = new models\Cart();
$user->getCarts()->add($cart);
$cart->setOwner($user);
$this->em->persist($cart);
$this->em->flush();
Here I get a blank screen. Without One-To-Many it works fine.