Ich habe zwei einfach Entities, diese sind über eine ManyToMany Verknüpfung verbunden. wenn ich nun nachfolgenden Code ausführe, kommt stets die Fehlermeldung: A new entity was found through the relationship ‘Shopware\CustomModels\JoeKaffeeAbo\Client#abos’ that was not configured to cascade persist operations for entity: Shopware\CustomModels\JoeKaffeeAbo\Abo@00000000211b173900000000cf7658ac. $client = new Client(); $client-\>setCustomerid(12); $client-\>setCustomernumber(12); $client-\>setIs\_active(true); Shopware()-\>Models()-\>persist($client); $abo = new Abo(); $abo-\>setName("name"); $abo-\>setDesc("desc"); $abo-\>setName\_en("name"); $abo-\>setDesc\_en("desc"); $client-\>addAbo($abo); //$abo-\>addClient($client); //$client-\>addAbo($abo); Shopware()-\>Models()-\>persist($client); //Shopware()-\>Models()-\>persist($abo); Shopware()-\>Models()-\>flush();
Die Models sehen folgendermaßen aus: [code]<?php namespace Shopware\CustomModels\JoeKaffeeAbo;
use Symfony\Component\Validator\Constraints as Assert,
Doctrine\Common\Collections\ArrayCollection,
Shopware\Components\Model\ModelEntity,
Doctrine\ORM\Mapping AS ORM;
/**
-
@ORM\Entity
-
@ORM\Table(name=“joe_kaffee_abo_abos”)
*/
class Abo extends ModelEntity
{public function __construct() {
$client = new ArrayCollection();
}/**
- Unique identifier
- @var integer
- @ORM\Column(name=“id”, type=“integer”, nullable=false)
- @ORM\Id
-
@ORM\GeneratedValue(strategy=“IDENTITY”)
*/
protected $id;
/**
-
@ORM\ManyToMany(targetEntity=“Shopware\CustomModels\JoeKaffeeAbo\Client”, inversedBy=“abos”, cascade={“persist”, “remove”})
**/
protected $clients;
/**
- @var string
-
@ORM\Column(name=“name”, type=“string”, length=255, nullable=true)
*/
protected $name = ‘’;
/**
- @var string
-
@ORM\Column(name=“desc”, type=“string”, length=255, nullable=true)
*/
protected $desc = ‘’;
/**
- @var string
-
@ORM\Column(name=“name_en”, type=“string”, length=255, nullable=true)
*/
protected $name_en = ‘’;
/**
- @var string
-
@ORM\Column(name=“desc_en”, type=“string”, length=255, nullable=true)
*/
protected $desc_en = ‘’;
public function addClient($client)
{
$this->clients = $client; } public function getId() { return $this->id; } public function getName() { return $this->name; } public function getDesc() { return $this->desc; } public function getName_en() { return $this->name_en; } public function getDesc_en() { return $this->desc_en; } public function setName($name) { $this->name=$name; return $this; } public function setDesc($desc) { $this->desc=$desc; return $this; } public function setName_en($name) { $this->name_en=$name; return $this; } public function setDesc_en($desc) { $this->desc_en=$desc; return $this; } } ?><?php namespace Shopware\CustomModels\JoeKaffeeAbo;
use Symfony\Component\Validator\Constraints as Assert,
Doctrine\Common\Collections\ArrayCollection,
Shopware\Components\Model\ModelEntity,
Doctrine\ORM\Mapping AS ORM;
/**
-
@ORM\Entity
-
@ORM\Table(name=“joe_kaffee_abo_client”)
*/
class Client extends ModelEntity
{public function __construct() {
$this->abos = new ArrayCollection(); } /** * Unique identifier * * @var integer * @ORM\Column(name=“id”, type=“integer”, nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy=“IDENTITY”) */ protected $id; /** * @ORM\ManyToMany(targetEntity=“Shopware\CustomModels\JoeKaffeeAbo\Abo”, mappedBy=“clients”, cascade={“persist”, “remove”}) **/ protected $abos = null; public function addAbo($abo) { $abo->addClient($this); $this->abos = $abo; } /** * @var integer * @ORM\Column(name=“customerid”, type=“integer”, nullable=true) */ protected $customerid; /** * @var integer * @ORM\Column(name=“customernumber”, type=“integer”, nullable=true) */ protected $customernumber; /** * @var boolean * @ORM\Column(name=“is_active”, type=“boolean”, nullable=true) */ protected $is_active; public function getId() { return $this->id; } public function getCustomerid() { return $this->customerid; } public function getCustomernumber() { return $this->customernumber; } public function getIs_active() { return $this->is_active; } public function setCustomerid($customerid) { $this->customerid = $customerid; return $this; } public function setCustomernumber($customernumber) { $this->customernumber=$customernumber; return $this; } public function setIs_active($is_active) { $this->is_active=$is_active; return $this; } } ?> [/code] Ich habs auch schon ohne der cascade Annotation versucht, aber hat auch nicht geklappt… bin ratlos!? Danke