当我试图用Doctrine 2连接两个表时,我遇到了一些问题。当我试图向表中添加一个新项时,我会得到以下错误:
通过未配置为级联持久化操作的关系找到了一个新实体:@。显式持久化新实体或配置级联持久化关系操作。
当我试图更新表中的一行时,我得到的是错误:
给定的实体没有身份。
我试图将胜利者实体事件id加入到事件的id中,以便为视图收集有关事件的数据。我不情愿地从更新的表单中获得返回的id,但它似乎不允许我更新它。
更新:因此,在处理了一些事情之后,当我添加cascade=“{持久化}”选项时,我得到一个未找到的错误,删除它并在其中添加完整的命名空间结果,声称该实体不存在.
<?php
namespace ZC\Entity;
/**
* ZC\Entity\Winner
*
* @Table(name="winner")
* @Entity(repositoryClass="ZC\Entity\Repository\Winner")
*/
class Winner
{
/**
* @var integer $id
*
* @Column(name="id", type="integer", nullable=false, unique=false, precision=0, scale=0)
* @Id
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $copy
*
* @Column(name="copy", type="text", length="", unique=false, nullable=true, precision=0, scale=0)
*/
protected $copy;
/**
* @var string $url
*
* @Column(name="url", type="string", length="255", unique=false, nullable=true, precision=0, scale=0)
*/
protected $url;
/**
*
* @ManyToOne(targetEntity="Events")
* @JoinColumns=({
* @JoinColumn(name="event", referencedColumnName="id")
* })
*
*/
protected $event;
/**
* __get function.
*
* @access protected
* @param mixed $property
* @return void
*/
public function __get($property) {
return $this->$property;
}
/**
* __set function.
*
* @access protected
* @param mixed $property
* @param mixed $value
* @return void
*/
public function __set($property, $value) {
$this->$property = $value;
}
}
<?php
namespace ZC\Entity;
/**
* ZC\Entity\Events
*
* @Table(name="events")
* @Entity(repositoryClass="ZC\Entity\Repository\Events")
*/
class Events
{
/**
* @var integer $id
*
* @Column(name="id", type="integer", nullable=false, unique=false, precision=0, scale=0)
* @Id
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $title
*
* @Column(name="title", type="string", length="255", unique=false, nullable=false, precision=0, scale=0)
*/
protected $title;
/**
* @var string $description
*
* @Column(name="description", type="text", length="", unique=false, nullable=true, precision=0, scale=0)
*/
protected $description;
/**
* @var string $status
*
* @Column(name="status", type="smallint", length="1", unique=false, nullable=false, precision=0, scale=0)
*/
protected $status = 0;
/**
* @var string $date
*
* @Column(name="date", type="string", length="255", unique=false, nullable=false, precision=0, scale=0)
*/
protected $date;
/**
* @var string $lang
*
* @Column(name="lang", type="string", length="255", unique=false, nullable=false, precision=0, scale=0)
*/
protected $lang;
/**
* __get function.
*
* @access protected
* @param mixed $property
* @return void
*/
public function __get($property) {
return $this->$property;
}
/**
* __set function.
*
* @access protected
* @param mixed $property
* @param mixed $value
* @return void
*/
public function __set($property, $value) {
$this->$property = $value;
}
}发布于 2012-09-05 16:34:33
使用cascade={"persist"}
/**
*
* @ManyToOne(targetEntity="Acme\Bundle\AcmeBundle\Entity\Events", cascade={"persist"})
* @JoinColumns=({
* @JoinColumn(name="event", referencedColumnName="id")
* })
*
*/
protected $event;https://stackoverflow.com/questions/12283764
复制相似问题