2

我有区域实体和 regionEmploymentDetails、regionEducationDetails、regionPowerDetails 实体,它们包含区域就业、教育和权力详细信息。实体是分开的,因为它们拥有不同的数据。下面是类,

class Region
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     *@ORM\OneToOne(targetEntity="RegionEducationDetails")
      @ORM\JoinColumn(name="region_id", referencedColumnName="id")
    **/

    private $education_details;

    /**
     *@ORM\OneToOne(targetEntity="RegionEmploymentDetails")
      @ORM\JoinColumn(name="region_id", referencedColumnName="id")
    **/

    private $employment_details; 

    /**
     *@ORM\OneToOne(targetEntity="RegionPowerDetails")
      @ORM\JoinColumn(name="region_id", referencedColumnName="id")
    **/

    private $power_details;
}

class RegionEducationDetails
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="region_id", type="integer", length=20)
     */
    private $region_id;
}

class RegionEmploymentDetails
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="region_id", type="integer")
     */
    private $region_id;
}

class RegionPowerDetails
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="region_id", type="integer")
     */
    private $region_id;
}

问题是当我使用命令生成模式时

php 应用程序/控制台原则:模式:更新 --force

它生成数据库表,但仅将 Region 实体与 RegionPowserDetails 实体相关联,并且不与其他实体相关联。

它似乎只考虑最后一个映射,因此只与最后一个实体相关。如果我删除权力实体关系,它与权力之前的实体相关,即就业。

我做错什么了吗?这个问题有什么解决办法吗?

4

1 回答 1

1

区域类应该是,

class Region {

/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;


private $education_details_id;

/**
 *@ORM\OneToOne(targetEntity="RegionEducationDetails")
  @ORM\JoinColumn(name="education_details_id", referencedColumnName="id")
**/

private $education_details;


private $employment_details_id; 

/**
 *@ORM\OneToOne(targetEntity="RegionEmploymentDetails")
  @ORM\JoinColumn(name="employment_details_id", referencedColumnName="id")
**/

private $employment_details; 


private $power_details_id;

/**
 *@ORM\OneToOne(targetEntity="RegionPowerDetails")
  @ORM\JoinColumn(name="power_details_id", referencedColumnName="id")
**/

private $power_details;

}
于 2013-02-08T12:37:55.293 回答