由于我是Symfony的新手,我尝试使用Doctrine创建实体关系。我收到错误属性“报告”在“[bundle / entity / file_location”已经声明,但是当我尝试更新架构时,它必须只声明一次“。
我已经关注了Symfony文档,但找不到解决方案。
实体/ 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;
}
}
实体/ 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;
}
}
学说/ 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
学说/ 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
答案 0 :(得分:3)
在Doctrine中,您不应将关系列声明为字段。
从report
移除Doctrine/ReportFile.orm.yml
字段,但保留manyToOne关系。 Doctrine将自己创建列。