php - Doctrine :: Relation ManyToOne will not work -
i got parentclass this
/** @orm\mappedsuperclass */ class basevalue { /** * @var int * * @orm\id * @orm\column(name="id", type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @var field * @orm\onetomany(targetentity="field", mappedby="value", cascade="all") */ protected $field; /** * @return int */ public function getid() { return $this->id; } /** * @param int $id */ public function setid($id) { $this->id = $id; } /** * @return field */ public function getfield() { return $this->field; } /** * @param field $field */ public function setfield($field) { $this->field = $field; } }
and child this
* @orm\entity * @orm\table(name="integers") */ class integer extends basevalue { /** * @var integer * * @orm\column(name="value", type="integer", nullable=true) */ protected $value; /** * @return string */ public function getvalue() { return $this->value; } /** * @param string $value */ public function setvalue($value) { $this->value = $value; } }
now relate child in class this
* @orm\entity * @orm\table(name="fields") */ class field { /** * @var int * * @orm\id * @orm\column(name="id", type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @var * @orm\manytoone(targetentity="basevalue", mappedby="field", cascade="all") * @orm\joincolumn(name="vid", referencedcolumnname="id") */ protected $value; // not work
it gets me following error: [doctrine\common\annotations\annotationexception]
[creation error] annotation @orm\manytoone declared on property zmpim\entity\field::$value not have property named "mappedby". available properties: targetentity, cascade, fetch, inversedby
both got mappedby,.. error seems senseless
cu n00n
your entity field inversed side of mapping instead of using mappedby declaration have use this
/** * inversed side * @var int|null * @orm\manytoone(targetentity="basevalue", inversedby="field") * @orm\joincolumn(name="[your_name]", referencedcolumnname="[id]", ondelete="cascade") */ protected $value;
to understand inversedside , mappedby attributes can read this: doctrine inverse , owning side
after reading again aware of relationnal problem between 2 of entities, if declare manytoone annotation, have set inversedby attribute or you'll error. , have. can't declare manytoone annotation mappedby attribute because not exist , throw exception doctrine.
to resume :
manytoone association =>
* @orm\manytoone(targetentity="[yourentity]", inversedby="[field]")
be careful side require declaration of :
* @orm\joincolumn(name="[your_name]", referencedcolumnname="[id]", ondelete="cascade")
onetomany =>
* @orm\onetomany(targetentity="[an_entity]", * mappedby="[field]", cascade={"persist"}, orphanremoval=true)
edit answer : mapping still incorrect, data in inversedby , mappedby need switched.
Comments
Post a Comment