[[PageOutline]] * [WikiPedia:Doctrine_(PHP)] = [https://phppackages.org/p/doctrine/dbal doctrine/dbal] = == Configuration and testing it == = [https://phppackages.org/p/doctrine/orm doctrine/orm] = == Doctrine Console == * http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html * https://sonata-project.org/bundles/admin/2-3/doc/getting_started/creating_an_admin.html {{{#!sh $ php bin/console doctrine:generate:entity --entity="AppBundle:Category" --fields="name:string(255)" --no-interaction $ php bin/console doctrine:generate:entity --entity="AppBundle:BlogPost" --fields="title:string(255) body:text draft:boolean" --no-interaction }}} == Relations == * //Les relations entre entités avec Doctrine2// [https://openclassrooms.com/courses/developpez-votre-site-web-avec-le-framework-symfony2/les-relations-entre-entites-avec-doctrine2 OpenClassrooms] * //Les relations entre entités dans Symfony2 avec Doctrine// [http://www.lafermeduweb.net/tutorial/les-relations-entre-entites-dans-symfony2-avec-doctrine-p97.html lafermeduweb] == Cascade == * doctrine ondelete * doctrine one to many cascade * //8. Working with Associations// [http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/working-with-associations.html readthedocs] * //Doctrine Cascade Options for OneToMany// [https://stackoverflow.com/questions/7709293/doctrine-cascade-options-for-onetomany stackoverflow] * //cascade={“remove”} VS orphanRemoval=true VS ondelete="CASCADE// [https://stackoverflow.com/questions/27472538/cascade-remove-vs-orphanremoval-true-vs-ondelete-cascade stackoverflow] == Events == * https://openclassrooms.com/courses/developpez-votre-site-web-avec-le-framework-symfony2/les-evenements-et-extensions-doctrine == Extensions - Behaviors == Gedmo are a standard, but Translatable is criticized * [https://packagist.org/packages/gedmo/doctrine-extensions gedmo/doctrine-extensions] * https://github.com/Atlantic18/DoctrineExtensions#extensions-and-documentation * https://github.com/Atlantic18/DoctrineExtensions/tree/master/doc * https://atlantic18.github.io/DoctrineExtensions/ * //Gedmo l'extension Doctrine 2 dans Symfony2// 2012 [http://julien.edouard.overblog.com/gedmo-l-extension-doctrine-2-dans-symfony2 overblog] * [https://packagist.org/packages/knplabs/doctrine-behaviors knplabs/doctrine-behaviors] === Compatibility Issues between Extensions === * SoftDeleteable - Sortable * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/softdeleteable.md#extra * Sluggable, Translatable and Tree * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#nesting-translatable-and-sluggable-extensions === Audit, Revision or Loggable === * Versioning of entities and their associations [https://packagist.org/packages/simplethings/entity-audit-bundle simplethings/entity-audit-bundle] * https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/audit.html * Loggable * Helps tracking changes and history of objects, also supports version management [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/loggable.md Gedmo] * Admin support [https://packagist.org/packages/picoss/sonata-extra-admin-bundle picoss/sonata-extra-admin-bundle] [https://github.com/picoss/SonataExtraAdminBundle/blob/master/Resources/doc/audit_manager.md doc/audit_manager] * [https://www.youtube.com/watch?v=wxgIHNtEN84 YouTube] * Loggable is able to track lifecycle modifications and log them using any third party log system [https://github.com/KnpLabs/DoctrineBehaviors#loggable KNP Labs] === Blameable === * Updates string or reference fields on create, update and even property change with a string or object (e.g. user) [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/blameable.md Gedmo] * Track creators and updators of a given entity [https://github.com/KnpLabs/DoctrineBehaviors#blameable KNP Labs] === Filterable === * Simple filter result [https://github.com/KnpLabs/DoctrineBehaviors#filterable KNP Labs] === Geocodable === * Extensions to PostgreSQL platform in order to work with cube and earthdistance extensions [https://github.com/KnpLabs/DoctrineBehaviors#geocodable KNP Labs] === IpTraceable === * Inherited from Timestampable, sets IP address instead of timestamp [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/ip_traceable.md Gedmo] === Joinable === * KNP Labs === Loggable (see Audit, Revision) === ==== References ==== * Supports linking Entities in Documents and vice versa [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/references.md Gedmo] === ReferenceIntegrity === * Constrains ODM MongoDB Document references [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/reference_integrity.md Gedmo] === Revision (see Audit, Loggable) === === Sluggable === * Urlizes your specified fields into single unique slug [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md Gedmo] * Sluggable generates slugs (uniqueness is not guaranteed) for an entity [https://github.com/KnpLabs/DoctrineBehaviors#sluggable KNP Labs] * Sluggable, Translatable and Tree (Compatibility issue) * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#nesting-translatable-and-sluggable-extensions === SoftDeleteable === * Allows to implicitly remove records [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/softdeleteable.md Gedmo] [https://github.com/KnpLabs/DoctrineBehaviors#softDeletable KNP Labs] * SoftDeleteable - Sortable (Compatibility issue) * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/softdeleteable.md#extra * Admin support [https://packagist.org/packages/picoss/sonata-extra-admin-bundle picoss/sonata-extra-admin-bundle] * keyword: SoftDeleteable * //StofDoctrineExtensionsBundle softdelete - How do I use it?// [https://stackoverflow.com/questions/16670454/stofdoctrineextensionsbundle-softdelete-how-do-i-use-it stackoverflow] * //Episode 39 - Utiliser l'extension softdeleteable avec Symfony2// DevAndClick [https://www.youtube.com/watch?v=kBzDiOFaRFY YouTube (fr)] === Sortable === * Makes any document or entity sortable [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sortable.md Gedmo] KNP Labs * SoftDeleteable - Sortable (Compatibility issue) * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/softdeleteable.md#extra === Timestampable === * Updates date fields on create, update and even property change [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md Gedmo] [https://github.com/KnpLabs/DoctrineBehaviors#timestampable KNP Labs] === Translatable === * Gives you a very handy solution for translating records into different languages [https://github.com/Atlantic18/DoctrineExtensions/blob/maste/doc/translatable.md Gedmo] * [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#example-code-to-use-personal-translations-with-symfony2-sonata-i18n-forms Example code to use Personal Translations with (Symfony2 Sonata) i18n Forms] * [https://github.com/KnpLabs/DoctrineBehaviors#translatable KNP Labs] * Sluggable, Translatable and Tree (Compatibility issue) * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#nesting-translatable-and-sluggable-extensions === Translator === * Explicit way to handle translations [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md Gedmo] === Tree === * This extension automates the tree handling process and adds some tree specific functions on repository. (closure, nestedset or materialized path) [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md Gedmo] [https://github.com/KnpLabs/DoctrineBehaviors#tree KNP Labs] * Sluggable, Translatable and Tree (Compatibility issue) * https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#nesting-translatable-and-sluggable-extensions === Uploadable === * Provides file upload handling in entity fields [https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/uploadable.md Gedmo] == Configuration and testing it == = [https://phppackages.org/p/doctrine/doctrine-bundle doctrine/doctrine-bundle] == Configuration and testing it == === Mapping Configuration === * When it appears unsure that ORM sees the mapped entities... {{{#!sh app$ php bin/console doctrine:mapping:info }}} {{{#!div class="important" [Exception] You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors. [[span(Symfony ~3.2.1, Doctrine 2.4, style=float: right)]] }}} * It may be needed to set "auto_mapping" to true (in orm section of config.yml) or to configure the orm in detail. * Once it is done: {{{#!sh app$ php bin/console doctrine:mapping:info Found 1 mapped entities: [OK] AppBundle\Entity\BlogPost }}} === Are the Mapped Entities in the Database Schema? === {{{#!sh app$ php bin/console doctrine:schema:validate [Mapping] OK - The mapping files are correct. [Database] FAIL - The database schema is not in sync with the current mapping file. }}} {{{#!sh app$ php bin/console doctrine:schema:update --force Updating database schema... Database schema updated successfully! "1" queries were executed }}} {{{#!sh app$ php bin/console doctrine:schema:validate [Mapping] OK - The mapping files are correct. [Database] OK - The database schema is in sync with the mapping files. }}} === Extract from command line history === ==== 2017-01-11 ==== php u018b_EasyAdmin.php doctrine:database:create composer require Sensio/Generator-Bundle {{{#!sh app$ php u018b_EasyAdmin.php generate:bundle --namespace=AppBundle --bundle-name=AppBundle --format=annotation --dir=../src --no-interaction }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:generate:entity --entity="AppBundle:BlogPost" --fields="title:string(255) body:text draft:boolean" --no-interaction }}} {{{#!div class="important" [InvalidArgumentException] Doctrine ORM Manager named "" does not exist. [[span(Symfony ~3.2.1, style=float: right)]] }}} {{{#!sh app$ php u018b_EasyAdmin.php cache:clear }}} {{{#!div class="important" [Symfony\Component\Config\Definition\Exception\InvalidTypeException] The configured class "AppBundle\Entity\BlogPost" for the path "easy_admin.entities.BlogPost" is no mapped entity. [[span(Symfony ~3.2.1, style=float: right)]] }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:schema:validate [Mapping] OK - The mapping files are correct. [Database] OK - The database schema is in sync with the mapping files. }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle/Entity/BlogPost Generating entity "AppBundle\Entity\BlogPost" }}} {{{#!div class="important" [Doctrine\ORM\Mapping\MappingException] Class "AppBundle\Entity\BlogPost" is not a valid entity or mapped super class. [[span(Symfony ~3.2.1, Doctrine 2.4, style=float: right)]] }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle/BlogPost Generating entities for namespace "AppBundle\BlogPost" }}} {{{#!div class="important" [RuntimeException] Namespace "AppBundle\BlogPost" does not contain any mapped entities. [[span(Symfony ~3.2.1, style=float: right)]] }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:mapping:info }}} {{{#!div class="important" [Exception] You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors. [[span(Symfony ~3.2.1, Doctrine 2.4, style=float: right)]] }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle Generating entities for bundle "AppBundle" }}} {{{#!div class="important" [RuntimeException] Bundle "AppBundle" does not contain any mapped entities. [[span(Symfony ~3.2.1, style=float: right)]] }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle Generating entities for bundle "AppBundle" > backing up BlogPost.php to BlogPost.php~ > generating AppBundle\Entity\BlogPost }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:mapping:info Found 1 mapped entities: [OK] AppBundle\Entity\BlogPost }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:schema:validate -vvv [Mapping] OK - The mapping files are correct. [Database] FAIL - The database schema is not in sync with the current mapping file. }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:schema:update --force Updating database schema... Database schema updated successfully! "1" queries were executed }}} {{{#!sh app$ php u018b_EasyAdmin.php doctrine:schema:validate -vvv [Mapping] OK - The mapping files are correct. [Database] OK - The database schema is in sync with the mapping files. }}} {{{#!div class="important" [[span(Symfony ~3.2.1, style=float: right)]] }}}