I have two simple entities (Client, Abo) connected with a ManyToMany 
association. When I try to execute the following statements I get the error 
below:

       $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();

The following error occurs:
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.


This are my two entities:

Abo:
---------

<?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"})
     * @ORM\JoinTable(name="joe_abos_clients")
     **/
    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;
    }   
}
?>


Client
---------
<?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;
    }   
}
?>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to