Doctrine orm 通过关系-错误找到了新实体
我试图建立两个表的简单关联。但我总是犯以下错误: 通过关系“Shopware\CustomModels\JoeKaffeeAbo\Client\abos”找到了一个新实体,该关系未配置为级联实体的持久化操作:Shopware\CustomModels\JoeKaffeeAbo\Abo@00000000211b173900000000cf7658ac 以下是我的模型:Doctrine orm 通过关系-错误找到了新实体,doctrine-orm,Doctrine Orm,我试图建立两个表的简单关联。但我总是犯以下错误: 通过关系“Shopware\CustomModels\JoeKaffeeAbo\Client\abos”找到了一个新实体,该关系未配置为级联实体的持久化操作:Shopware\CustomModels\JoeKaffeeAbo\Abo@00000000211b173900000000cf7658ac 以下是我的模型: <?php namespace Shopware\CustomModels\JoeKaffeeAbo; use Symfo
<?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 = '';
//getter and setters...
}
?>
这说明您需要在保存客户机之前保存Abo实体
$abo = new Abo();
$abo->setName("name");
$abo->setDesc("desc");
$abo->setName_en("name");
$abo->setDesc_en("desc");
Shopware()->Models()->persist($abo); //Persist the Abo before assigning it to the client
$client->addAbo($abo);
//$abo->addClient($client);
//$client->addAbo($abo);
Shopware()->Models()->persist($client);
//Shopware()->Models()->persist($abo);
Shopware()->Models()->flush();
$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();
$abo = new Abo();
$abo->setName("name");
$abo->setDesc("desc");
$abo->setName_en("name");
$abo->setDesc_en("desc");
Shopware()->Models()->persist($abo); //Persist the Abo before assigning it to the client
$client->addAbo($abo);
//$abo->addClient($client);
//$client->addAbo($abo);
Shopware()->Models()->persist($client);
//Shopware()->Models()->persist($abo);
Shopware()->Models()->flush();