問題を解決しようとするあらゆる試みを無視する問題に遭遇しました。それはおそらく簡単です、私はこれで完全に疲れ果てました:)
基本的に、ユーザーがモジュール (Facebook ID、略歴、テキスト入力) とアセット (画像ロゴ、PDF など) をページ オブジェクトに追加できるようにしたいと考えています。
モジュールとアセットからページへの一対一の関係を設定しました。
モジュールは期待どおりに機能しますが、アセットはまったく機能しません。PageController がそのエンティティから getAsset() を呼び出すと、null になります。アセットを繰り返し処理するまで、エラーは発生しません。
また、PageController には、次の名前空間宣言があります。
use Linkme\SiteBundle\Entity\Module;
use Linkme\SiteBundle\Entity\Asset;
Module 宣言を削除するとエラーが発生しますが、Asset 行を削除しても何も変わりません。したがって、私は関係が作成されていないと考えています。
私が走れば
app/console doctrine:schema:create --dump-sql
次に、とりわけ次の行を取得します。
ALTER TABLE Asset ADD CONSTRAINT FK_C36E75589D3B65E3 FOREIGN KEY (pageId) REFERENCES Page(id);
これにより、スキーマが正しいと思います。アセットがページに関連していることを少なくとも理解しています
タイプミスがあると感じ始めているか、明らかな何かが完全に欠けていると感じ始めています-トラブルシューティングやその他の提案に関する支援があれば大歓迎です!
app/console --version
Symfony version 2.0.1 - app/dev/debug
Page.php
/*
* @ORM\OneToMany(targetEntity="Asset", mappedBy="pageId", cascade={"persist", "remove"})
* @ORM\OrderBy({"type" = "ASC"})
* @ORM\OrderBy({"id" = "ASC"})
*
* @var ArrayCollection $assets
*/
protected $assets;
/**
* @ORM\OneToMany(targetEntity="Module", mappedBy="pageId", cascade={"persist", "remove"})
* @ORM\OrderBy({"type" = "ASC"})
* @ORM\OrderBy({"id" = "ASC"})
*
* @var ArrayCollection $modules
*/
protected $modules;
/**
* Set assets
* @param Asset $assets
*/
public function setAssets(Asset $assets = null)
{
$this->assets = $assets;
}
/**
* Get assets
*
* @return Asset
*/
public function getAssets()
{
echo '<br />Asset is '.gettype($this->assets); // outut: Asset is NULL
return $this->assets;
}
/**
* Set modules
* @param Module $modules
*/
public function setModules(Module $modules = null)
{
$this->modules = $modules;
}
/**
* Get modules
* @return Module
*/
public function getModules()
{
echo '<br />Module is '.gettype($this->assets); // output: Module is object
return $this->modules;
}
Asset.php
/**
* @var integer $pageId
*
* @ORM\ManyToOne(targetEntity="Page", inversedBy="assets")
* @ORM\JoinColumn(name="pageId", referencedColumnName="id")
*/
protected $pageId;
Module.php
/**
* @var integer $pageId
*
* @ORM\ManyToOne(targetEntity="Page", inversedBy="modules")
* @ORM\JoinColumn(name="pageId", referencedColumnName="id")
*/
protected $pageId;
PageController.php
use Linkme\SiteBundle\Entity\Module;
use Linkme\SiteBundle\Entity\Asset;
/**
* Add modules and assets to a page
*
* @Route("/{id}/wizardmodule", name="page_wizardmodule")
* @Template()
*/
public function wizardmoduleAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$page = $em->getRepository('LinkmeSiteBundle:Page')->find($id);
$modules = $page->getModules();
$assets = $page->getAssets();
depmod
[symfony]
git=http://github.com/symfony/symfony.git
version=v2.0.1
[twig]
git=http://github.com/fabpot/Twig.git
version=v1.1.2
[monolog]
git=http://github.com/Seldaek/monolog.git
version=1.0.1
[doctrine-common]
git=http://github.com/doctrine/common.git
version=2.1.1
[doctrine-dbal]
git=http://github.com/doctrine/dbal.git
version=2.1.1
[doctrine]
git=http://github.com/doctrine/doctrine2.git
version=2.1.1
[swiftmailer]
git=http://github.com/swiftmailer/swiftmailer.git
version=v4.1.1
[assetic]
git=http://github.com/kriswallsmith/assetic.git
version=v1.0.1
[twig-extensions]
git=http://github.com/fabpot/Twig-extensions.git
[metadata]
git=http://github.com/schmittjoh/metadata.git
version=1.0.0
[SensioFrameworkExtraBundle]
git=http://github.com/sensio/SensioFrameworkExtraBundle.git
target=/bundles/Sensio/Bundle/FrameworkExtraBundle
version=v2.0.1
[JMSSecurityExtraBundle]
git=http://github.com/schmittjoh/JMSSecurityExtraBundle.git
target=/bundles/JMS/SecurityExtraBundle
version=v2.0.1
[SensioDistributionBundle]
git=http://github.com/sensio/SensioDistributionBundle.git
target=/bundles/Sensio/Bundle/DistributionBundle
version=v2.0.1
[SensioGeneratorBundle]
git=http://github.com/sensio/SensioGeneratorBundle.git
target=/bundles/Sensio/Bundle/GeneratorBundle
version=v2.0.1
[AsseticBundle]
git=http://github.com/symfony/AsseticBundle.git
target=/bundles/Symfony/Bundle/AsseticBundle
version=v1.0.0