I want to generate Entities from an Existing Database by using Doctrine tools for reverse engineering
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 AcmeBlogBundle annotation
2 $ php app/console doctrine:generate:entities AcmeBlogBundle
but now the doctrine detect only ManyToOne relation in many side only "ProviderCountry" table
if i need to add the ManyToMany relation i have to add the annotation by my hand by adding the follwing annotation
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;
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;
so how can I generate Many-To-Many annotation by doctrine command [doctrine:mapping:import]
Thanks in advance.
you can do this by add the following lines in
vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
inside __construct
Note: That will override OneToMany annotation.
I wouldn't recommend you to modify the vendor. You should modify your schema and generate the entities and the database after.
In your case I would modify the schema after you generated it from database
Symfony2 Jobeet - The Data Model