I've got a problem setting up the Doctrine mapping correctly.
I have a CashRegister
Entity which has a bin location and a return bin location. Both locations are from the same Type (BinLocation
Entity).
Outgoing from CashRegister
, CashRegister->getBinLocations()
and CashRegister->getReturnBinLocations()
are working fine, but how can I achieve that BinLocation->getCashRegisters()
returns all CashRegister
Entities that are referenced (binLocation
+ returnBinLocation
)?
/**
* CashRegister
*
* @ORM\Table(name="cash_registers")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class CashRegister
{
...
/**
* @var BinLocation
*
* @ORM\ManyToOne(targetEntity="BinLocation", inversedBy="cashRegisters")
* @ORM\JoinColumn(name="bin_location_id", referencedColumnName="id")
*/
private $binLocation;
/**
* @var BinLocation
*
* @ORM\ManyToOne(targetEntity="BinLocation", inversedBy="cashRegisters")
* @ORM\JoinColumn(name="return_bin_location_id", referencedColumnName="id")
*/
private $returnBinLocation;
/**
* @return BinLocation
*/
public function getBinLocation()
{
return $this->binLocation;
}
/**
* @return BinLocation
*/
public function getReturnBinLocation()
{
return $this->returnBinLocation;
}
...
}
/**
* BinLocation
*
* @ORM\Table(name="bin_locations")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class BinLocation
{
...
/**
* @var CashRegister[]
*
* @ORM\OneToMany(targetEntity="CashRegister", mappedBy="binLocation") <= Here is the problem, in this case mappedBy need to be an array [binLocation, returnBinLocation]
*/
private $cashRegisters;
/**
* @return CashRegister[]
*/
public function getCashRegisters()
{
return $this->cashRegisters;
}
...
}