Introduction to the Doctrine ORM and data mapper pattern in php -


In this tutorial we will see how to take our first steps with Doctrine, a data mapper pattern implementation that is part of the Symfony php framework, but can also be used on its own.

This is a companion discussion topic for the original entry at



Thanks, that great and simple.
Now, the most difficult is to retrieve all posts from the Author entity.
If i remember, you must add an ArrayCollection empty in the constructor and add getPosts(), setPosts(), AddPosts() and removePosts() to be efficients between Author and Posts Entities.
I don’t know if this can be added automatically by the command “doctrine orm:generate-entities” after the “OneToMany”.


Egidio Docile -> gilles

Yes, you are correct: using orm:generate-entities will also take care of generating the constructor, which will include the initialization of ArrayCollection objects. The methods you mentioned will also be automatically generated.


Petr Filippov

PHP Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException: Class “entities\Author” is not a valid entity or mapped super class. in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:346

what im doing wrong?

Now everything is working


Thanks 4 that important tuto
I have problem generation getters and setters
When typing following in windows cmd

php vendor/bin/doctrine orm:generate-entities

i’m having that output

dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../doctrine/orm/bin" && pwd)

if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
   # We are in Cgywin using Windows php, so the path must be translated
   dir=$(cygpath -m "$dir");

"${dir}/doctrine" "$@"

I need help