gpt4 book ai didi

Symfony2 : Error "Property was already declared, but it must be declared only once"

转载 作者:行者123 更新时间:2023-12-04 12:52:12 30 4
gpt4 key购买 nike

由于我是 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;
}
}

实体/报告文件.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 中,您不应该将关系列声明为字段。

删除 report字段来自 Doctrine/ReportFile.orm.yml但留下 manyToOne 关系。 Doctrine 将自行创建列。

关于Symfony2 : Error "Property was already declared, but it must be declared only once",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28420144/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com