# How to assign categories to Product entity via DAL

**URL:** <https://forum.shopware.com/t/how-to-assign-categories-to-product-entity-via-dal/85747>\
**Category:** Programming (EN)\
**Created:** [5. März 2021 um 15:32 UTC](https://forum.shopware.com/t/how-to-assign-categories-to-product-entity-via-dal/85747 "2021-03-05T15:32:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://forum.shopware.com/u/dev)\
**Post date:** [5. März 2021 um 15:32 UTC](https://forum.shopware.com/t/how-to-assign-categories-to-product-entity-via-dal/85747/1 "2021-03-05T15:32:21Z")

</div>

Hi Guys!

I’m starting with developing Shopware modules and probably I don’t understand everything yet, and because of that, I’ve stuck. Maybe someone will be able to help me.

I’m trying to assign/unassign the product categories via [DAL](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/updating-entities-dal). At first, I’ve tried to set `categoryTree` key in the `update` function, but it’s read-only field.

Then I’ve tried to use `product_category` repository for managing entities there, but when I try to search items by specific criteria I’m getting the error that is described [here](https://issues.shopware.com/issues/NEXT-7497).

Which repository or what entity should I use to assign or unassign the categories to the product via DAL? Maybe there is a function in `ProductEntity` that I don’t see?

Thank you!

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://forum.shopware.com/u/dev)\
**Post date:** [8. März 2021 um 08:43 UTC](https://forum.shopware.com/t/how-to-assign-categories-to-product-entity-via-dal/85747/3 "2021-03-08T08:43:20Z")

</div>

Thank you! I’ve tried to use `categories` key, but I didn’t know that the categories there must be structured with `['id' => 'XXX']` array. After changing that everything works fine!

Do you know, how in a such approach unassign the specific category? It looks that this approach could be only used for adding the categories, but not for removing.

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://forum.shopware.com/u/dev)\
**Post date:** [19. März 2021 um 10:52 UTC](https://forum.shopware.com/t/how-to-assign-categories-to-product-entity-via-dal/85747/5 "2021-03-19T10:52:31Z")

</div>

Thank you! That works 🙂
