php - Auto generate Doctrine-Entity from existing Table -


i'm trying auto generate entities from specific table of database. don't want send doctrine on whole database, because there tables in not compatible doctrine (like tables legacy database having no primary keys [yes...]).

unfortunately, blog posts , so-anwers doesn't help, parameter "--filter" isn't working supposed.

what i've done:

i tried first step so-answer , read blog post.

php app/console doctrine:mapping:convert metadata_format \     ./src/app/userbundle/resources/config/doctrine \     --from-database \     --filter="user" 

i understood filter-argument solution filter specific table. filter not being applied. process gets canceled exception "table xyz has no primary key" (what true here , not part of question).

i guess create complete new database without problematic tables creating annotations , entities. i'm wondering written process , why not work.

update

i tried out suggestions first answer:

php app/console doctrine:mapping:import --force acmeblogbundle yml 

acmeblogbundle placeholder real bundle. import task stops with:

[symfony\component\debug\exception\contexterrorexception]
warning: class_parents(): class action not exist , not loaded

the first table called "action". when drop table, stops simular exception @ next table.

update 2

the exception mentioned lines above caused due previous used orm-implementation having classes "actionentity.php" within directory called "entity" each table. thats why exception happened think. after dropped directory, exception disappeared (but isn't solution in case).

what did now: dropped foreign keys (they made troubles), setup new symfony project, run these comments first answer here , got pre-generated entity classes, without foreign keys implementation. things have add now, including several changes database scheme because doctrine 2 has restrictions here not supporting primary keys foreign keys , that. can pick entity-classes , adjust missing connections other entities.

all in all: whole process not satisfying ...

from documentation:

as doctrine tools documentation says, reverse engineering one-time process started on project. doctrine able convert approximately 70-80% of necessary mapping information based on fields, indexes , foreign key constraints. doctrine can't discover inverse associations, inheritance types, entities foreign keys primary keys or semantical operations on associations such cascade or lifecycle events. additional work on generated entities necessary afterwards design each fit domain model specificities.

right steps import entities database:

  1. php bin/console doctrine:mapping:import --force acmeblogbundle xml
  2. php bin/console doctrine:mapping:convert annotation ./src
  3. php bin/console doctrine:generate:entities acmeblogbundle

you can use xml or yml, worked only xml case.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -