My Code:
$item = new Entity\Item();
$item->setAccountId($account["id"]);
$item->setCategory((string)$data->category);
$item->setRegion((string)$data->region);
$item->setFlag(0);
$item->setRank(0);
$item->setPhone("");
$item->setEmail("");
$item->setURL((string)$data->url);
$item->setTags($tags);
//var_dump($item);
//die();
$this->em->persist($item);
$this->em->flush();
$this->em->clear();
Annotation Relationship:
/////////////////////////////////////////////////////////////////////////
// Relations //
/////////////////////////////////////////////////////////////////////////
/**
* @ManyToOne(targetEntity="Account", inversedBy="items")
* @JoinColumn(name="account_id", referencedColumnName="id")
*/
private $account;
/////////////////////////////////////////////////////////////////////////
// ForeingKey //
/////////////////////////////////////////////////////////////////////////
/**
* @Column(type="integer")
*/
protected $account_id;
If i use old doctrine (2.0) the code work, if i set to 2.2 , code throw this exception:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'account_id' cannot be null
In 2.2 i need to use the Parent entity to insert a Chield entity?