本文介绍了Symfony2 Doctrine2 - 通过doctrine从现有数据库生成多对多注释:mapping:import的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用Doctrine工具来进行逆向工程来生成来自现有数据库的实体

I want to generate Entities from an Existing Database by using Doctrine tools for reverse engineering

您可以要求Doctrine导入模式并构建相关的实体类,方法是执行以下两个命令。

you can ask Doctrine to import the schema and build related entity classes by executing the following two commands.

1 $ php app / console doctrine:mapping:import AcmeBlogBu​​ndle注释

$ 2 $ php应用程序/控制台原则:生成:实体AcmeBlogBu​​ndle

但现在的原则只检测ManyToOne关系在许多方面只有ProviderCountry表

but now the doctrine detect only ManyToOne relation in many side only "ProviderCountry" table

如果我需要添加ManyToMany关系,我必须通过添加以下注释来添加注释

if i need to add the ManyToMany relation i have to add the annotation by my hand by adding the follwing annotation

在Country.php中添加

in Country.php add

/**
 *
 * @var Provider $provider
 *
 * @ORM\ManyToMany(targetEntity="Provider")
 * @ORM\JoinTable(name="provider_country",
 *      joinColumns={@ORM\JoinColumn(name="countryId", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="providerId", referencedColumnName="id")}
 *      )
 * */
private $providers;

在Provider.php中添加

in Provider.php add

  /**
     * @var Country $country
     *
     * @ORM\ManyToMany(targetEntity="Country")
     * @ORM\JoinTable(name="provider_country",
     *      joinColumns={@ORM\JoinColumn(name="providerId", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="countryId", referencedColumnName="id")}
     *      )
     * */
    private $countrys;

所以如何通过doctrine命令生成多对多注释[doctrine:mapping:import]

so how can I generate Many-To-Many annotation by doctrine command [doctrine:mapping:import]

提前感谢

推荐答案

vendor / doctrine / orm / lib / Doctrine / ORM / Mapping / Driver / DatabaseDriver.php

vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php

 $tables = array();
    $tables[] = $schemaManager->listTableDetails("country");
    $tables[] = $schemaManager->listTableDetails("provider_country");
    $tables[] = $schemaManager->listTableDetails("provider");
    $this->setTables($schemaManager->listTables(), $tables);

里面__construct

inside __construct

public function __construct(AbstractSchemaManager $schemaManager)

注意:
这将覆盖OneToMany注释。

Note:That will override OneToMany annotation.

这篇关于Symfony2 Doctrine2 - 通过doctrine从现有数据库生成多对多注释:mapping:import的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:45