Doctrine2加入错误

时间:2013-11-14 03:24:59

标签: doctrine-orm

类实体

**
 * classes
 *
 * @ORM\Table(name="classes")
 * @ORM\Entity
 * @Annotation\Name("classes")
 * @Annotation\Hydrator("Zend\Stdlib\Hydrator\ClassMethods")
 */
class Classes {

      /**
     * @var integer
     *
     * @ORM\Column(name="class_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @Annotation\Exclude()
     */
     protected $classId;

     /**
     * @var string
     *
     * @ORM\Column(name="class_name", type="string", length=100, nullable=false)
     * @Annotation\Filter({"name":"StringTrim"})
     * @Annotation\Validator({"name":"StringLength", "options":{"min":1, "max":30}})
     * @Annotation\Validator({"name":"Regex", "options":{"pattern":"/^[a-zA-Z][a-zA-Z0-9_-]{0,24}$/"}})
     * @Annotation\Attributes({"type":"text"})
     * @Annotation\Options({"label":"class name:"})  
     */
    private $className; 
}

实体Maptechclass

/** @ORM\Entity */
class Maptechclass {

    /**
     * @var integer
     *
     * @ORM\Column(name="map_tech_class_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @Annotation\Exclude()
     */
    protected $mapTechClassID;

    /**
     * @var integer
     *
     * @ORM\Column(name="map_sch_id", type="integer", nullable=true)

     */
    protected $mapSchID;

    /**
     * @var integer
     *
     * @ORM\Column(name="map_tech_id", type="integer", nullable=true)

     */
    protected $mapTechID;

    /**
     * @ORM\OneToMany(targetEntity="SchoolAdmin\Entity\Classes")
     * @ORM\JoinColumn(name="map_class_id", referencedColumnName="classId")
     * */
    protected $mapClassID;
}

将显示以下错误,如何修复它。 字段'mapClassID'上的OneToMany映射需要'mappedBy'属性。

1 个答案:

答案 0 :(得分:1)

查找

@ORM\OneToMany(targetEntity="SchoolAdmin\Entity\Classes")

将其替换为:

@ORM\OneToMany(targetEntity="SchoolAdmin\Entity\Classes", mappedBy="classId")