1
我已经建立2个实体
User
和Photo
Symfony2的关系的两个实体,ArrayCollection的
现在我想创建一个一对多的关系。
假设我有这样的代码在User
实体类:
// User.php
/**
* @ORM\OneToMany(targetEntity="Photo", mappedBy="user")
*/
protected $photos;
public function __construct()
{
$this->photos = new ArrayCollection();
}
当我添加照片的形式进入用户的形态,类似于它是如何在这段代码做
// UserType.php
public function buildForm(FormBuilder $builder, array $options)
{
// ...
$builder->add('photos', new PhotoType());
}
它抛出:
Expected argument of type "Acme\UserBundle\Entity\Photo", "Doctrine
\Common\Collections\ArrayCollection" given
那么我怎样才能将照片的形式添加到用户的形式?
PS对不起,我的英语
分子不是我uderstand?你想说我什么? – 2012-03-04 10:27:18