Table Mapping using Doctrine 2, in Symfony 2 in YAML

Hello techs,

I hope you are doing good 🙂  Recently, I have been working on a Symfony 2 project and in Symfony 2, the data layer is managed by using Doctrine ORM. So today, I planned to post an article on how to correctly map an existing data table using Doctrine 2.x object relationship mapping (ORM) techniques.  Later, (in next post) I will be showing how to map a relationship such as one-to-one, one-to-many, many-to-one, unidirectional and bidirectional using the same Doctrine ORM techniques.

Before continuing the Doctrine mapping procedure, we need a pre built table. This table can be any database format. For the sake of easiness I will be using a very simple MySQL data table.  The name of the table is ‘user’ and table looks like this,


Column Name Data Type Attributes
id integer primary key, auto increment, not null
first_name string not null
last_name string not null
email string
mobile Integer length 11
date_of_birth date
f_key_1 Integer unique

Continue reading