次のフィクスチャをデータベースに追加しようとしています:
$pageContent1 = new pageContent();
$pageContent1->addPageSector($this->getReference('ps1'));
$pageContent1->addPageSector($this->getReference('ps2'));
$pageContent1->setPageTypes($this->getReference('pt2'));
*$pageContent1->setPageParent(10);*
$pageContent1->setPageName('Paragraphs');
$pageContent1->setRichText('<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>');
$manager->persist($pageContent1);
アスタリスクで囲まれた行は、1 対 1 の関係でページの親ページを参照していると思われる問題を引き起こしている行です。
しかし、次のエラーが発生します。
[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to acme\StyleGuideBundle\Entity
\pageContent::setPageParent() must be an instance of acme\StyleGuideBund
le\Entity\pageParent, integer given, called in /Volumes/Projects/Style Guid
e/site/acmeGuidelines/src/acme/StyleGuideBundle/DataFixtures/ORM/Page
sContentFixtures.php on line 21 and defined in /Volumes/Projects/Style Guid
e/site/acmeGuidelines/src/acme/StyleGuideBundle/Entity/pageContent.ph
p line 300
エラーが参照する関数は、このセッターにあります。
/**
* Set pageParent
*
* @param \acme\StyleGuideBundle\Entity\pageParent $pageParent The parent page of this page
*
* @return pageContent
*/
public function setPageParent(\acme\StyleGuideBundle\Entity\pageParent $pageParent = null)
{
$this->pageParent = $pageParent;
return $this;
}
これは doctrine:generate:entities を使用してこのエンティティから自動的に生成されました:
/**
* @ORM\OneToOne(targetEntity="pageContent")
* @ORM\JoinColumn(name="pageParent", referencedColumnName="id")
*/
private $pageParent;
上記の「targetEntity」はコンテナ クラスの名前です。それが正しいかどうかはわかりませんでしたが、他に何を設定すればよいかわかりませんでした。