wiki:members/GRIP-UQAM/Doctrine_(PHP)

doctrine/dbal

Configuration and testing it

doctrine/orm

Doctrine Console

Relations

Cascade

  • doctrine ondelete
  • doctrine one to many cascade
  • 8. Working with Associations readthedocs
  • Doctrine Cascade Options for OneToMany// stackoverflow
  • cascade={“remove”} VS orphanRemoval=true VS ondelete="CASCADE stackoverflow

Events

Extensions - Behaviors

Gedmo are a standard, but Translatable is criticized

Compatibility Issues between Extensions

Audit, Revision or Loggable

Blameable

  • Updates string or reference fields on create, update and even property change with a string or object (e.g. user) Gedmo
  • Track creators and updators of a given entity KNP Labs

Filterable

Geocodable

  • Extensions to PostgreSQL platform in order to work with cube and earthdistance extensions KNP Labs

IpTraceable

  • Inherited from Timestampable, sets IP address instead of timestamp Gedmo

Joinable

  • KNP Labs

Loggable (see Audit, Revision)

References

  • Supports linking Entities in Documents and vice versa Gedmo

ReferenceIntegrity

  • Constrains ODM MongoDB Document references Gedmo

Revision (see Audit, Loggable)

Sluggable

SoftDeleteable

Sortable

Timestampable

Translatable

Translator

  • Explicit way to handle translations Gedmo

Tree

Uploadable

  • Provides file upload handling in entity fields Gedmo

Configuration and testing it

doctrine/doctrine-bundle

Configuration and testing it

Mapping Configuration

  • When it appears unsure that ORM sees the mapped entities...
    app$ php bin/console doctrine:mapping:info
    

    [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. Symfony ~3.2.1, Doctrine 2.4

  • 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:
    app$ php bin/console doctrine:mapping:info
    Found 1 mapped entities:
    [OK]   AppBundle\Entity\BlogPost
    

Are the Mapped Entities in the Database Schema?

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.
app$ php bin/console doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "1" queries were executed
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

app$ php u018b_EasyAdmin.php generate:bundle --namespace=AppBundle --bundle-name=AppBundle --format=annotation --dir=../src --no-interaction
app$ php u018b_EasyAdmin.php doctrine:generate:entity --entity="AppBundle:BlogPost" --fields="title:string(255) body:text draft:boolean" --no-interaction

[InvalidArgumentException] Doctrine ORM Manager named "" does not exist. Symfony ~3.2.1

app$ php u018b_EasyAdmin.php cache:clear

[Symfony\Component\Config\Definition\Exception\InvalidTypeException] The configured class "AppBundle\Entity\BlogPost" for the path "easy_admin.entities.BlogPost" is no mapped entity. Symfony ~3.2.1

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.
app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle/Entity/BlogPost
Generating entity "AppBundle\Entity\BlogPost"

[Doctrine\ORM\Mapping\MappingException] Class "AppBundle\Entity\BlogPost" is not a valid entity or mapped super class. Symfony ~3.2.1, Doctrine 2.4

app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle/BlogPost
Generating entities for namespace "AppBundle\BlogPost"

[RuntimeException] Namespace "AppBundle\BlogPost" does not contain any mapped entities. Symfony ~3.2.1

app$ php u018b_EasyAdmin.php doctrine:mapping:info

[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. Symfony ~3.2.1, Doctrine 2.4

app$ php u018b_EasyAdmin.php doctrine:generate:entities AppBundle
Generating entities for bundle "AppBundle"

[RuntimeException] Bundle "AppBundle" does not contain any mapped entities. Symfony ~3.2.1

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
app$ php u018b_EasyAdmin.php doctrine:mapping:info
Found 1 mapped entities:
[OK]   AppBundle\Entity\BlogPost
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.
app$ php u018b_EasyAdmin.php doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "1" queries were executed
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.

Symfony ~3.2.1

Last modified 3 years ago Last modified on Jan 12, 2017, 2:30:48 PM