2015-02-09 143 views
1

由於我是Symfony的新手,我嘗試使用Doctrine創建實體關係。我收到錯誤「[bundle/entity/file_location」中的屬性「report」已經聲明,但必須聲明一次「當我嘗試更新架構時Symfony2:錯誤「屬性已被聲明,但必須聲明一次」

我遵循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 

回答

3

教義,你應該不申報關係的列字段。

Doctrine/ReportFile.orm.yml刪除report字段,但留下manytoOne關係。學說將自行創建列。

+0

非常感謝您爲我工作! – 2015-02-09 22:14:28