Symfony2:错误 "Property was already declared, but it must be declared only once"
Symfony2: Error "Property was already declared, but it must be declared only once"
由于我是 Symfony 的新手,我尝试使用 Doctrine 创建实体关系。我收到错误 属性 "report" in "[bundle/entity/file_location" was already declared, but it must be declared only once" 当我尝试更新架构。
我已按照 Symfony 文档进行操作,但找不到解决方案。
Entity/Report.php
<?php
namespace Aurora\ReportBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Report
*/
class Report
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
/**
* var array
*/
private $reportFiles;
public function _construct() {
$this->reportFiles = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Report
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
* @return Report
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
}
Entity/ReportFile.php
<?php
namespace Aurora\ReportBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ReportFile
*/
class ReportFile
{
/**
* @var integer
*/
private $id;
/**
* @var Report
*/
private $report;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $path;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get report
*
* @return integer
*/
public function getReport()
{
return $this->report;
}
/**
* Set report
*
* @param integer $report
* @return ReportFile
*/
public function setReport($report)
{
$this->report = $report;
return $this;
}
/**
* Set name
*
* @param string $name
* @return ReportFile
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set path
*
* @param string $path
* @return ReportFile
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
}
Doctrine/Report.orm
Aurora\ReportBundle\Entity\Report:
type: entity
table: null
repositoryClass: Aurora\ReportBundle\Entity\ReportRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
description:
type: text
lifecycleCallbacks: { }
oneToMany:
reportFiles:
targetEntity: ReportFile
mappedBy: report_id
Doctrine/ReportFile.orm.yml
Aurora\ReportBundle\Entity\ReportFile:
type: entity
table: null
repositoryClass: Aurora\ReportBundle\Entity\ReportFileRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
report:
type: integer
column: report_id
name:
type: string
length: 255
path:
type: string
length: 255
lifecycleCallbacks: { }
manyToOne:
report:
targetEntity: Report
inversedBy: reportFiles
joinColumn:
name: report_id
referencedColumnName: id
在 Doctrine 中,您不应该将关系列声明为字段。
从 Doctrine/ReportFile.orm.yml
中删除 report
字段但保留多对一关系。 Doctrine 会自己创建专栏。
由于我是 Symfony 的新手,我尝试使用 Doctrine 创建实体关系。我收到错误 属性 "report" in "[bundle/entity/file_location" was already declared, but it must be declared only once" 当我尝试更新架构。
我已按照 Symfony 文档进行操作,但找不到解决方案。
Entity/Report.php
<?php
namespace Aurora\ReportBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Report
*/
class Report
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
/**
* var array
*/
private $reportFiles;
public function _construct() {
$this->reportFiles = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Report
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
* @return Report
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
}
Entity/ReportFile.php
<?php
namespace Aurora\ReportBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ReportFile
*/
class ReportFile
{
/**
* @var integer
*/
private $id;
/**
* @var Report
*/
private $report;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $path;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get report
*
* @return integer
*/
public function getReport()
{
return $this->report;
}
/**
* Set report
*
* @param integer $report
* @return ReportFile
*/
public function setReport($report)
{
$this->report = $report;
return $this;
}
/**
* Set name
*
* @param string $name
* @return ReportFile
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set path
*
* @param string $path
* @return ReportFile
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
}
Doctrine/Report.orm
Aurora\ReportBundle\Entity\Report:
type: entity
table: null
repositoryClass: Aurora\ReportBundle\Entity\ReportRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
description:
type: text
lifecycleCallbacks: { }
oneToMany:
reportFiles:
targetEntity: ReportFile
mappedBy: report_id
Doctrine/ReportFile.orm.yml
Aurora\ReportBundle\Entity\ReportFile:
type: entity
table: null
repositoryClass: Aurora\ReportBundle\Entity\ReportFileRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
report:
type: integer
column: report_id
name:
type: string
length: 255
path:
type: string
length: 255
lifecycleCallbacks: { }
manyToOne:
report:
targetEntity: Report
inversedBy: reportFiles
joinColumn:
name: report_id
referencedColumnName: id
在 Doctrine 中,您不应该将关系列声明为字段。
从 Doctrine/ReportFile.orm.yml
中删除 report
字段但保留多对一关系。 Doctrine 会自己创建专栏。