OroCRM allows creating custom bundles with different functionality. And working with OroCRM you may notice that bundles without an entity is a rare case. It is not difficult process and you can easily create an entity with different configurations. But what if you want to remove an entity? In our article we share the tips on how to do it correctly.
Very often when we try to remove any custom entity or change namespace of an entity we receive the error:
[Doctrine\ORM\Mapping\MappingException] The target-entity Atwix\Bundle\TestBundle\Entity\Test cannot be found in 'Atwix\Bundle\TestBundle\Entity\Test#test.
So, how can we fix it? The solution is quite simple, you need to run few commands after removing the entity. First of all, remove all data related to that entity from the database:
app/console oro:entity-config:debug "Atwix\Bundle\TestBundle\Entity\Test" --attr="state" --scope="extend" --set --val="Deleted"
As a next step, remove data related to the entity ownership:
app/console oro:entity-config:debug "Atwix\Bundle\TestBundle\Entity\Test" --scope ownership --remove
Then, update the config of the entity:
app/console oro:entity-config:update
And update the config of the entity “extend”:
app/console oro:entity-extend:update-config
As a final step, we should update its schema:
app/console oro:entity-extend:update-schema
Of course, do not forget to clear the cache:
php app/console cache:clear -e dev php app/console cache:clear -e prod
Furthermore, if you need to remove few entities, you do not have to run the described above commands for all of them separately. To save your time, just execute first two commands for each entity that you plan to remove and then run the remaining three commands for those entities together.
As you can see, the process of entity removing is quite easy. But it is very important to follow the described steps to do it correctly and avoid any errors.
We hope this brief article will save your time for debugging when you are removing entities. Thank you for reading us.