私はManyToOne、OneToOneリレーションを持つエンティティを持っています。私は別のエンティティを持っています。これは最初のエンティティにリンクされています。最初のエンティティとそれに関連する他のエンティティに関する情報を取得することです。Doctrine 2関連するエンティティからアイテムを取得する
私は何らかの理由で呼び出しを行うと、関連するエンティティでNULLを返します。
コード:
<?php
namespace App\Model\Entities;
use Doctrine\ORM\Mapping as ORM,
Doctrine\Common\Collections\ArrayCollection;
use Kdyby\Doctrine\Entities\BaseEntity;
/**
* Doctrine entity for resorts in destinations
* @package App\Model\Entities
* @ORM\Entity
*/
class Resort extends BaseEntity
{
/**
* autoincremented resort id
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* resort name
* @ORM\Column(type="string")
*/
protected $title;
/**
* @ORM\OneToOne(targetEntity="ResortProperties", mappedBy="resort", cascade={"persist"})
*/
private $properties;
public function __construct()
{
$this->properties = new ArrayCollection();
}
/**
* HERE I WANT TO GET DATA FROM ANOTHER ENTITY
* @return type
*/
public function getProperties()
{
return $this->properties;
}
}
および関連エンティティはこれです:
<?php
namespace App\Model\Entities;
use Doctrine\ORM\Mapping as ORM,
Doctrine\Common\Collections\ArrayCollection;
use Kdyby\Doctrine\Entities\BaseEntity;
/**
* Doctrine entity for resort properties
* @package App\Model\Entities
* @ORM\Entity
*/
class ResortProperties extends BaseEntity
{
/**
* autoincremented id
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* resort id
* @ORM\OneToOne(targetEntity="Resort", inversedBy="Resort", cascade={"persist", "remove"})
* @ORM\JoinColumn(onDelete="CASCADE")
*/
protected $resort;
/**
* parameter1
* @ORM\Column(type="string")
*/
protected $parameter1;
}
私が期待し、私はすべてのリゾートエンティティを取得し、Resort->properties
になり$repository->findAll();
を呼び出すときResortPropertyエンティティを結合することであろうと、それはNULLです。
私は何が間違っているのか分かりませんが、誰かが私の間違いを指摘できますか?ありがとう
ありがとう、私はいくつかの変更を加えなければならなかった、私は分 – WellBloud