I have an issue with a ManyToOne - OneToMany relation with Doctrine 2 x Symfony 3..
I created 2 Entities (let's name them IPAddress and VPS), one VPS can have many ips and many ips can belong to a VPS
My IPAddress Entity:
class IPAddress
{
....
/**
* Many IPs have one server
*
* @ORM\ManyToOne(targetEntity="VPS", inversedBy="ips")
*/
protected $server;
/**
* @return mixed
*/
public function getServer()
{
return $this->server;
}
/**
* @param mixed $server
*/
public function setServer($server)
{
$this->server = $server;
}
....
}
My VPS Entity :
Class VPS
{
....
/**
* One server have many IPs
*
* @ORM\OneToMany(targetEntity="IPAddress", cascade={"persist", "remove"}, mappedBy="server")
*/
protected $ips;
public function __construct()
{
$this->ips = new ArrayCollection();
}
/**
* @return mixed
*/
public function getIps()
{
return $this->ips;
}
/**
* @param mixed $ips
*/
public function addIps(IPAddress $IPAddress)
{
$this->ips->add($IPAddress);
$IPAddress->setServer($this);
}
....
}
When I try to get the IPs through my VPS like this :
$em = $this->getDoctrine()->getManager();
$serverRepo = $em->getRepository('AppBundle:VPS');
$server = $serverRepo->find(4);
$server->getIps();
//From there, there is no way to get my IPs, I only have a very big object without my IPs informations, only my columns' names marked as "null"
May someone have any idea and could help me with that issue? I'm searching since a day and can't find what I'm doing wrong..
Thanks in advance! :)