pra*_*iri 2 entity-relationship doctrine symfony
由于我是 Symfony 的新手,我尝试使用 Doctrine 创建实体关系。当我尝试更新架构时,我收到错误“[bundle/entity/file_location”中的属性“report”已声明,但必须仅声明一次”。
我遵循了 Symfony 文档,但找不到解决方案。
实体/报告.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;
}
}
Run Code Online (Sandbox Code Playgroud)
实体/报告文件.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;
}
}
Run Code Online (Sandbox Code Playgroud)
教义/报告.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
Run Code Online (Sandbox Code Playgroud)
学说/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
Run Code Online (Sandbox Code Playgroud)
在 Doctrine 中,您不应该将关系列声明为字段。
report从中删除字段Doctrine/ReportFile.orm.yml但保留 manyToOne 关系。Doctrine 将自行创建列。
| 归档时间: |
|
| 查看次数: |
7130 次 |
| 最近记录: |