# QueryBuilder Kategorie mit like auf custom field

**URL:** https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924
**Category:** Programmierung
**Created:** [8. Dezember 2017 um 10:47 UTC](https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924 "2017-12-08T10:47:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)
#### Post date: [8. Dezember 2017 um 10:47 UTC](https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924/1 "2017-12-08T10:47:57Z")

</div>

```
 Ich möchte eine Abfrage gestalten die mir alle Kategorien gibt welche einen Wortteil in einem Custom Field haben: $builder-\>select(['category', 'attribute']) -\>from(\Shopware\Models\Category\Category::class, 'category') -\>leftJoin('category.attribute', 'attribute') -\>where('attribute.ln\_my\_custom\_field like :test') -\>setParameter('test', '%test%');

```

&nbsp;

Laut Exception hat aber Category das Feld ln\_my\_custom\_field nicht.

&nbsp;

```
 [Semantical Error] line 0, col 130 near 'ln\_my\_custom\_field': Error: Class Shopware\\Models\\Attribute\\Category has no field or association named ln\_my\_custom\_field"
```

---

<div class="post-metadata">

### Author: ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)
#### Post date: [8. Dezember 2017 um 11:21 UTC](https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924/2 "2017-12-08T11:21:08Z")

</div>

Geh jetzt vorerst mal nicht über die models sondern direkt per sql, was solls -\_-

```
 $builder = $this-\>container-\>get('dbal\_connection')-\>createQueryBuilder(); $builder-\>select(['categoryID', 'ln\_my\_custom\_field']) -\>from('s\_categories\_attributes', 'cat\_at') -\>where('cat\_at.ln\_my\_custom\_field like :test') -\>setParameter('test', '%test%'); $categoriesArrayData = $builder-\>execute()-\>fetchAll();
```

---

<div class="post-metadata">

### Author: ![h\_lohaus](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@h\_lohaus](https://forum.shopware.com/u/h_lohaus)
#### Post date: [10. Dezember 2017 um 08:51 UTC](https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924/3 "2017-12-10T08:51:45Z")

</div>

Hi,

das Feld ist im Model CamelCase Beispiel:

```
 -\>where('attribute.lnMyCustomField like :test') 

```

Gruß Heiner

---

<div class="post-metadata">

### Author: ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)
#### Post date: [11. Dezember 2017 um 08:27 UTC](https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924/4 "2017-12-11T08:27:49Z")

</div>

Trifft dies auch zu wenn man das custom field so anlegt ?

```
        $service->update(
            's_categories_attributes',
            'ln_my_custom_field',
            TypeMapping::TYPE_STRING,
            [
                'displayInBackend' => true,
                'label' => 'Test Field',
                'supportText' => 'Testing'
            ]
        );

```

&nbsp;

---

<div class="post-metadata">

### Author: ![h\_lohaus](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@h\_lohaus](https://forum.shopware.com/u/h_lohaus)
#### Post date: [11. Dezember 2017 um 08:46 UTC](https://forum.shopware.com/t/querybuilder-kategorie-mit-like-auf-custom-field/49924/5 "2017-12-11T08:46:41Z")

</div>

Ja. Gruß Heiner
