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
Here is a link to docs i followed:
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.
**
* @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 Comments 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
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 !