1

I have three tables "category", "product" and "product_category". First two tables are created from two entity Category and Product. Third table "product_category" is auto generated by framework doctrine console command.

Now I can get (fetch) product relational data (based on category id) from below query, which is fine.

$this->createQueryBuilder('p')
                ->leftJoin('p.category', 'c')
                ->select('p')
                ->where('c.id = :category_id')
                ->setParameter('category_id', 2)
                ->getQuery()->getSQL();

But how can I use Many-to-Many relation to Update Data? I had Tried with several queries but its not working!!! ( I want to update all product status to inactive (2), whose category status is (2 = Inactive).

Kiran
  • 1,176
  • 2
  • 14
  • 27

1 Answers1

0

When doing a query on a table that has children. You can also just fetch the parent item, and doctrine will automatically handle the child objects. If you have a getCategory within the Product entity, it will resolve the category automatically.

Probably what you are looking for is cascading of events. of which is explained within Doctrine 2 ManyToMany cascade

Matt Smeets
  • 398
  • 4
  • 15