background preloader

Doctrine2

Facebook Twitter

Welcome to the Doctrine Project — Doctrine-Project. Entities' generation from an existing database. So I began working on Symfony2 framework, i had to map an existing database with Doctrine2.

Entities' generation from an existing database

First of all, keep in mind that Doctrine2 gives its best for creating a schema, not for generating an object model from an existing one. It's therefore important to "prepare" your database before generation unless you'll get an approximative model... You must define a Primary Key on each table of your DB. Doctrine 2 in Depth. Association Examples One–To–One unidirectional Here is an example of a Product that has one Shipping object associated to it.

Doctrine 2 in Depth

Because the Shipping object does not refer to the Product being shipped, it is unidirectional relationship. <? Php/** @ORM\Entity */class Product { // ... /** * @ORM\OneToOne(targetEntity="Shipping") * @ORM\JoinColumn(name="shipping_id", referencedColumnName="id") */ private $shipping; // ...} /** @ORM\Entity */class Shipping { // ...}