1

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.

Community
  • 1
  • 1
PiTheNumber
  • 22,828
  • 17
  • 107
  • 180

1 Answers1

0

Ok, I figured it out myself. The trick was to show error messages:

error_reporting(E_ALL);
ini_set('display_errors', '1');

I needed to fill some fields with values. There were not allowed to be null. DOH!

PiTheNumber
  • 22,828
  • 17
  • 107
  • 180