Symfony2形成了许多关系

时间:2015-10-25 19:08:55

标签: symfony

(Symfony版本2.7)

嗨,我在字段中有很多关系存在问题。

Class Notification {

public function __construct()
{
    $this->assigneduser = new \Doctrine\Common\Collections\ArrayCollection();
    $this->flags = new ArrayCollection();
}

/**
 * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Flag", inversedBy="notificationflags", cascade={"persist"})
 * @ORM\JoinTable(name="sla_notificationflags",
 *                  joinColumns={@ORM\JoinColumn(name="notification_id", referencedColumnName="notificationId")},
 *                  inverseJoinColumns={@ORM\JoinColumn(name="flag_id", referencedColumnName="flagId")}
 *               )
 *
*/
private $flags;

/**
 * Add flag
 *
 * @param \AppBundle\Entity\Flag $flag
 * @return Notification
 */
public function addFlag(Flag $flag)
{
    $flag->addNotificationflag($this);
    $this->flags[] = $flag;
    return $this;
}

}

Class Flag {

public function __construct()
{
    $this->notificationflags = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Notification", mappedBy="flags")
 */
protected $notificationflags;

/**
 * Add notificationflags
 *
 * @param \AppBundle\Entity\Notification $notificationflag
 * @return Flag
 */
public function addNotificationflag(Notification $notificationflag)
{

    if(!$this->notificationflags->contains($notificationflag)) {
        $this->notificationflags->add($notificationflag);
    }

    return $this;
}



}

我的表格类

class NotificationSingleFormType extends AbstractType
{

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('flags','entity',array(
            'label' => false,
            'attr' => array(
                'class' => 'select'
            ),
            'class' => 'AppBundle\Entity\Flag',
            'query_builder' => function(EntityRepository $er) {
                return $er->createQueryBuilder('p')
                    ->addOrderBy('p.name','ASC');
            },
            'property' => 'name',
            'required' => false
    )
    );
}

}

当我发送表格时,我看到错误:

  

财产"标志&#34>也不是其中一种方法   " addFlag()" /" removeFlag()"," setFlags()"," flags()",&# 34; __集()"要么   " __呼叫()"在课堂上存在并具有公共访问权限   "的appbundle \实体\通知"

1 个答案:

答案 0 :(得分:0)

你必须生成getter / setter并添加/删除flag属性的方法。

使用php app/console doctrine:generate:entities自动生成