Symfony 5: Mastering Doctrine Relations
The ManyToOne Relation
  Unlock this challenge
Login Register

Challenge 2 / 2

I'm trying to relate a Product object to a Category... but it's not working. What's wrong with my code?

$category = new Category();
// ...

$product->setCategory($category->getId());

$entityManager->persist($product);
$entityManager->persist($category);

$entityManager->flush();
Skip challenges and go to theNext Chapter

Turn Challenges Off?

All further challenges will be skipped automatically.
You can re-enable challenges at any time on this page or from your account page.