尝试使用Doctrine 2连接两个表时遇到一些问题。当我尝试向表中添加新项时,我收到错误:
通过未配置为级联持久操作的关系找到新实体:@。明确保留新实体或在关系上配置级联持久操作。
当我尝试更新表格中的一行时,我收到错误:
给定实体没有身份。
我正在尝试将获胜者实体事件ID加入到事件的ID中,以便我可以收集视图事件的数据。我正在从更新的表单中获取返回的id,但它似乎不允许我更新它。
更新 所以我已经玩了一些东西,当我添加cascade =“{persist}”选项时,我得到一个类未找到错误,删除它并添加完整的命名空间结果声明该实体不存在...
<?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;
}
}
答案 0 :(得分:1)
使用cascade={"persist"}
:
/**
*
* @ManyToOne(targetEntity="Acme\Bundle\AcmeBundle\Entity\Events", cascade={"persist"})
* @JoinColumns=({
* @JoinColumn(name="event", referencedColumnName="id")
* })
*
*/
protected $event;