ikodev
ikodev

Reputation: 49

add doctrine orm on existing database without defining all associations

I work on a php project which was using some symfony components such as the serializer and router for examples but without the SF framework. All classes are hand-made and was not using namespaces, the project was having it's proper autoloader of classes.

My first task was to install and configure SF3 on that project in order to "homogenize" the development.

For that, I have included all the project in a FirstBundle and have identified/isolated classes which are rather Entities or Repositories or Managers or Services etc...also I have defined all namespaces and the doctrine DBAL component in place of the classic singleton php class :) All works fine on a Symfony base installation now.

In a same time I have developed a SecondBundle that add new functionalities on the project, this one is more SF-friendly of course but both bundles are associated by foreign keys on mysql.

Now, I would like to find a way to "connect" the doctrine ORM without having to "convert" all project entities (by setting the orm definitions). A step-by-step method could be nice.

I did some tests by adding all doctrine orm annotations on the SecondBundle, however my problem is the existing mysql associations that force me to add doctrine annotations on the FirstBundle too if I want the datas-integrity to be preserved ! (many-to-many, one-to-one, many-to-one...)

Is there a way to avoid the management of some associations by the orm and to let mysql manage them in a first step ? I speak about the associations BETWEEN the two bundles :)

Thank you !

Guillaume

Upvotes: 0

Views: 560

Answers (1)

Michał G
Michał G

Reputation: 2302

As i understood, you have some legacy code written in plain php . And you want to migrate it to SF

I think that a good start w'll be to try create entities (with associations ) in SF with this command ,and try to work with this

console doctrine:mapping:import 

https://symfony.com/doc/current/doctrine/reverse_engineering.html

Upvotes: 1

Related Questions