Reputation: 107
I have one class B with 4 array collection :
class B {
private $FWs;
private $FXs;
private $FYs;
private $FZs;
...
}
Each class FW, FX, FY, FZ extend an other abstract class F.
I would like to do this :
b->getFWs();
b->getFXs();
b->getFYs();
b->getFZs();
fw->getB();
fx->getB();
fy->getB();
fz->getB();
I don't know which annotation should i put :
abstract class F {
/**
* @OMR\ManyToOne(targetEntity="B", inversedBy= ? )
*/
private $b;
}
class B {
/**
* @ORM\OneToMany(targetEntity= ?, mappedBy="b")
*/
private $FWs;
...
}
Can you help me. Thank.
Upvotes: 1
Views: 109
Reputation: 3135
If you set $b as protected in your abstract classe, annotations set on children will be added to parent annotations.
(If someone arrive here and want to override annotations he has to do it like it is explained here)
Just define your ManyToOne relations in your children classes :
abstract class F {
protected $b;
}
class FW extends F{
/**
* @OMR\ManyToOne(targetEntity="B", inversedBy= "FWs" )
*/
protected $b;
}
class FX extends F {
/**
* @OMR\ManyToOne(targetEntity="B", inversedBy= "FXs" )
*/
protected $b;
}
...
class B {
/**
* @ORM\OneToMany(targetEntity= "FW", mappedBy="b")
*/
private $FWs;
/**
* @ORM\OneToMany(targetEntity= "FX", mappedBy="b")
*/
private $FXs;
...
}
Upvotes: 1