# How make Shopware.form.field.Search works with ManyToOne association in backend with ExtJs?

**URL:** <https://forum.shopware.com/t/how-make-shopware-form-field-search-works-with-manytoone-association-in-backend-with-extjs/59977>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [12. Juni 2019 um 14:31 UTC](https://forum.shopware.com/t/how-make-shopware-form-field-search-works-with-manytoone-association-in-backend-with-extjs/59977 "2019-06-12T14:31:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![komoito](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@komoito](https://forum.shopware.com/u/komoito)\
**Post date:** [12. Juni 2019 um 14:31 UTC](https://forum.shopware.com/t/how-make-shopware-form-field-search-works-with-manytoone-association-in-backend-with-extjs/59977/1 "2019-06-12T14:31:13Z")

</div>

Hi guys!

I am using Shopware version 5.5 and currently im working with Shopware.form.field.Search display on my detail view. ManyToOne association. I follow the docs but there is no example of it only some code snipets so i am not sure about how it should work&nbsp;

Here is a link to docs i followed:  
[https://developers.shopware.com/developers-guide/backend-components/associations/](https://developers.shopware.com/developers-guide/backend-components/associations/)

So here is the code:

I have Comment entity that want to use with specific shop.&nbsp;

```
**
 * @ORM\Entity
 * @ORM\Table(name="kt_shop_comments", options={"collate"="utf8_unicode_ci"})
 */
class ShopComments extends ModelEntity
{

 /**
     * @var int
     *
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\Column(name="image", type="string")
     */
    private $image;

    /**
     * @var string
     * 
     * @ORM\Column(name="customer_name", type="string")
     */
    private $customerName;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string")
     */
    private $name;

    /**
     * @var string
     * 
     * @ORM\Column(name="subtitle", type="string")
     */
    private $subtitle;
    
    /**
     * @var string
     * 
     * @ORM\Column(name="text", type="text")
     */
    private $text;

    /**
     * @var string
     * 
     * @ORM\Column(name="article_number", type="string")
     */
    private $articleNumber;

    /**
     * @var Shop
     *
     * @ORM\ManyToOne(targetEntity="Shopware\Models\Shop\Shop")
     * @ORM\JoinColumn(name="shop_id",referencedColumnName="id")
     *
     */
    private $shop;

    /**
     * @ORM\Column(name="shop_id", type="integer")
     */
    private $shopId

 /**
     * @return Shop
     */
    public function getShop()
    {
        return $this->shop;
    }

    /**
     * @param Shop $shop
     */
    public function setShop($shop)
    {
        $this->shop = $shop;
    }

    public function getId(){
        return $this->id;
    }

    public function getImage(){
        return $this->image;        
    }

    public function setImage($image){
        $this->image = $image;
    }

    public function getCustomerName(){
        return $this->customerName;        
    }

    public function setCustomerName($customerName){
        $this->customerName = $customerName;        
    }

    public function getName(){
        return $this->name;
    }

    public function setName($customerName){
        $this->name = $customerName;
    }

    public function getSubtitle(){
        return $this->subtitle;
    }

    public function setSubtitle($subtitle){
        $this->subtitle = $subtitle;
    }

    public function getText(){
        return $this->text;
    }

    public function setText($text){
        $this->text = $text;
    }

    public function getArticleNumber(){
        return $this->articleNumber;
    }

    public function setArticleNumber($articleNumber){
        $this->articleNumber = $articleNumber;
    }
}

```

**And i configured my backend model&nbsp; Comments&nbsp;in ExtJs like that:**

```
Ext.define('Shopware.apps.ShopCommentsEdit.model.ShopComments', {
    extend: 'Shopware.data.Model',
    
    configure: function () {
        return {
            controller: 'ShopCommentsEdit',
            detail: 'Shopware.apps.ShopCommentsEdit.view.detail.Comment'
        };
    },
    
    fields: [
        {
            name: 'id', type: 'int', useNull: true
        },
        {
            name: 'image', type: 'string'
        },
        {
            name: 'customerName', type: 'string'
        },
        {
            name: 'name', type: 'string'
        },
        {
            name: 'subtitle', type: 'string'
        },
        {
            name: 'text', type: 'string'
        },
        {
            name: 'articleNumber', type: 'string'
        },
        {
            name: 'shopId', type: 'int'
        }
    ],

    associations: [{
        relation: 'ManyToOne',
        field: 'shopId',
        type: 'hasMany',
        model: 'Shopware.apps.Base.model.Shop',
        name: 'getShop',
        associationKey: 'shop'
    }]

});

```

And here is my comment detial component:

```
Ext.define('Shopware.apps.ShopCommentsEdit.view.detail.Comment', {
    extend: 'Shopware.model.Container',
    alias: 'widget.shop-comments-detail-view',

    configure: function(){
            return {
                controller: 'ShopCommentsEdit',
                fieldSets: [
                    {
                        title: 'Comment attributes',
                        layout: 'fit',
                        fields: {
                            customerName: {},
                            name: {},
                            subtitle: {},
                            articleNumber: {},
                            image: {
                                xtype: 'mediafield',
                                name: 'image',
                                valueField: 'virtualPath'
                            },
                            shopId: {}
                        }
                    },
                    {
                        title: 'Comment text',
                        layout: 'fit',
                        fields: {
                            text: this.createDescription
                        }
                    }
                ]
            }
    },

    createDescription: function(model, formField) {
        formField.xtype = 'textarea';
        formField.height = 90;
        formField.grow = true;
        return formField;
     }
});

```

And when i go to shop backend i have nice looking combo search box

 ![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/5/532c3113aa8a31e2ed9f2470745610c64ab59074.png)

But when i click it get asscociation error message:

```
Oops! An error has occurred! The following notes should help you. Association name expected, 'shop' is not an association. in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 3057 Stack trace: #0 engine/Shopware/Controllers/Backend/Application.php(936): 

```

Any idea what i am doing wrong ?

Thanks for help !

---

<div class="post-metadata">

**Author:** ![komoito](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@komoito](https://forum.shopware.com/u/komoito)\
**Post date:** [13. Juni 2019 um 07:24 UTC](https://forum.shopware.com/t/how-make-shopware-form-field-search-works-with-manytoone-association-in-backend-with-extjs/59977/2 "2019-06-13T07:24:02Z")

</div>

Hi guys! I just wanted to you to know that I fixed that i just had to add to my backend controller those lines:

```
   protected function getDetailQuery($id) {
        $builder = parent::getDetailQuery($id);

        $builder->leftJoin('shop_comments.shop','shop');
        $builder->addSelect(['shop']);

        return $builder;
    }

    protected function getListQuery() {
        $builder = parent::getListQuery();

        $builder->leftJoin('shop_comments.shop','shop');
        $builder->addSelect([('shop')]);

        return $builder;
    }

```

I just missed them in documentation ! :)&nbsp;

---

<div class="post-metadata">

**Author:** ![CWR](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@CWR](https://forum.shopware.com/u/CWR)\
**Post date:** [30. April 2020 um 06:11 UTC](https://forum.shopware.com/t/how-make-shopware-form-field-search-works-with-manytoone-association-in-backend-with-extjs/59977/3 "2020-04-30T06:11:15Z")

</div>

Hallo Komoito.  
Kannst du ein Screenshot deiner Ordner-Struktur für dieses Plugin posten? Das würde mir mit einem ähnlichen Problem helfen. Danke

&nbsp;

---

<div class="post-metadata">

**Author:** ![komoito](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@komoito](https://forum.shopware.com/u/komoito)\
**Post date:** [22. Mai 2020 um 07:51 UTC](https://forum.shopware.com/t/how-make-shopware-form-field-search-works-with-manytoone-association-in-backend-with-extjs/59977/4 "2020-05-22T07:51:54Z")

</div>

> [@CWR schrieb:](https://forum.shopware.com/profile/34989/CWR "CWR")
> 
> Hallo Komoito.  
> Kannst du ein Screenshot deiner Ordner-Struktur für dieses Plugin posten? Das würde mir mit einem ähnlichen Problem helfen. Dan

Sorry, I can’t it is a private project, but if you want i can help you if you describie your problem here.&nbsp;
