0

別のオブジェクトの属性であるオブジェクトを削除したいのですが、これを実行すると、「エンティティが見つかりませんでした」という例外が発生します。</ p>

私が言っていることの例:

// Foo has a private property, bar, which is an instance of Bar
$foo = $this->get('my_bundle.repository.foo')->find($fooId);
$bar = $foo->getBar();

$entityManager = $this->get('doctrine.orm.entity_manager');
$entityManager->remove($bar);
$entityManager->flush();

Barこれは、以下が機能しているように見えるため、エンティティマネージャがのインスタンスを直接ロードしなかったためだと思います。

// Foo has a private property, bar, which is an instance of Bar
$foo = $this->get('my_bundle.repository.foo')->find($fooId);
$bar = $this->get('my_bundle.repository.foo')->find($bar->getId());

$entityManager = $this->get('doctrine.orm.entity_manager');
$entityManager->remove($bar);
$entityManager->flush();

リロードせずにこれを機能させる方法はあり$barますか?

4

1 に答える 1

0

問題は、エンティティマネージャをフラッシュするときに、FooがプロパティとしてBarを保持していることです。行う

$foo->setBar(null);
$entityManager->persist($foo);

フラッシュを行う前に

于 2012-09-02T21:21:19.780 に答える