简体   繁体   中英

zf2 generating entity with doctrine ORM

I have Entity classes generated with Doctrine ORM, and ZF2.

I changed a table structure and I want to update an entity class, so I am trying to regenerate the entity class but it's not working.

I used the following code:

vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Album\\Entity\\" --force --from-database annotation ./module/Album/src/clear

I got the error:

[Doctrine\\ORM\\Mapping\\MappingException]
Property "status" in "Album\\Entity\\TestRun" was already declared, but it must be declared only once
orm:convert-mapping [--filter="..."] [--force] [--from-database] [--extend[="..."]] [--num-spaces[="..."]] [--namespace[="..."]] to-type dest-path

I want to re-generate the entity class for a particular table

If you change the structure of your Entity file a simple \\vendor\\bin\\doctrine-module orm:schema-tool:update --force will alter the table according to your Entity definition.

If you still want to recreate the table simple drop the table from your mysql and run the update command. You may have some cache files left so clearing those might be a good Idea, too.

You can clear the complete cache like so:

\vendor\bin\doctrine-module orm:clear-cache:query 
\vendor\bin\doctrine-module orm:clear-cache:result
\vendor\bin\doctrine-module orm:clear-cache:metadata

As mentioned above it might be a bad practice, but nevertheless I use the following commands to achieve the result you are asking about:

vendor\bin\doctrine-module orm:convert-mapping --filter='Evaluation' --namespace='MyModule\Entity\\' --force --from-database annotation ./module/MyModule/src/   

and another command to generate getters and setters:

vendor\bin\doctrine-module orm:generate-entities --filter='Evaluation' ./module/MyModule/src/ --generate-annotations=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM