Entity relations not updated during same kernel request #8622
Unanswered
kswzr
asked this question in
Support Questions
Replies: 1 comment
-
It took me a while to see this, public function setProduct(Product $product)
{
$this->product = $product;
$product->addComponent($this);
}
// and Product:
public function addComponent(ProductComponent $component)
{
$this->productComponents[] = $component;
} If you are not updating this, then the call to `ProductRepository::find($productId)`` will return the reference that you loaded before and that was initialized. Another way to fix this is to detach the reference after using: em->persist($productComponent);
$em->flush();
$em->detach($product); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
i have two entity objects: Product, ProductComponent. One product can have multiple components.
First creating the Product entity, persisting and flushing with the EntityManager.
Second, creating product component, but without knowledge about the real Product object, just having the id of the product:
When I am accessing now the
$productRepository
from a new kernel request, the returned product will have the component relations.What's the reason for that? Is something missing?
Beta Was this translation helpful? Give feedback.
All reactions