学说 双向关系在某些价值观上无法访问



我有一个多人的问题 - 与学说2 x Symfony 3 ..

我创建了2个实体(让我们命名ipaddress和VPS(,一个VP可以具有许多IP,许多IP可以属于VPS

我的iPaddress实体:

class IPAddress
{
    ....
    /**
     * Many IPs have one server
     *
     * @ORMManyToOne(targetEntity="VPS", inversedBy="ips")
     */
    protected $server;
    /**
     * @return mixed
     */
    public function getServer()
    {
        return $this->server;
    }
    /**
     * @param mixed $server
     */
    public function setServer($server)
    {
        $this->server = $server;
    }
    ....
}

我的VPS实体:

Class VPS
{
    ....
    /**
     * One server have many IPs
     *
     * @ORMOneToMany(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);
    }
    ....
}

当我尝试通过这样的VP获取IPS时:

$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"

有人可能有任何想法,可以帮助我解决这个问题吗?我从一天开始搜索,找不到我在做错什么。

预先感谢!:(

在此处查看示例。http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association/association-mapping.html#one-to-to-to-many-bidirectional

学说2不能在许多关系中使用nullable = false?

相关内容

  • 没有找到相关文章

最新更新