I got a ParentClass like 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 a child like 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 I would like to relate the child in another class like 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; // but it does not work
It always gets me the following error:
[Doctrine\Common\Annotations\AnnotationException]
[Creation Error] The annotation @ORM\ManyToOne declared on property zmpim\Entity\Field::$value does not have a property named "mappedBy". Available properties: targetEntity, cascade, fetch, inversedBy
Both got mappedby,.. so the error seems to be senseless
Update:
A field has got values and labels. The values get inherited from BaseValue into IntegerValue, StringValue and later others...
My OneToMany Relation is a parent class of inheritance. like this, now:
/** @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="field", cascade="persist", orphanRemoval=true )
*/
protected $field;
And this is my ManyToOne:
/**
*
* @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 int|null
* @ORM\ManyToOne(targetEntity="BaseValue", inversedBy="value")
* @ORM\JoinColumn(name="vid", referencedColumnName="id", onDelete="CASCADE")
*/
protected $value;
It still give me an error, but now it is:
[Doctrine\ORM\ORMException]
Column nameid
referenced for relation from zmpim\Entity\Field towards zmpim\Entity\BaseValue does not exist.