Symfony2:错误“已声明属性,但必须只声明一次”

问题描述 投票:1回答:1

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

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
symfony doctrine entity-relationship
1个回答
3
投票

在Doctrine中,您不应将关系列声明为字段。

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

© www.soinside.com 2019 - 2024. All rights reserved.