Symfony2 from scratch

#Reverse engineering only
#DB => XML
$ php app/console doctrine:mapping:import --force FooBarBundle xml
Importing mapping information from "default" entity manager
  > writing ~\Foo\BarBundle/Resources/config/doctrine/Foo.orm.xml

# XML Example
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
	xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
	<entity name="Foo\BarBundle\Entity\User" table="user">

		<indexes>
			<index name="name_idx" columns="name" />
			<index columns="email" />
		</indexes>

		<unique-constraints>
			<unique-constraint columns="name,email" name="search_idx" />
		</unique-constraints>

		<lifecycle-callbacks>
			<lifecycle-callback type="prePersist" method="doStuffOnPrePersist" />
			<lifecycle-callback type="prePersist"
				method="doOtherStuffOnPrePersistToo" />
			<lifecycle-callback type="postPersist" method="doStuffOnPostPersist" />
		</lifecycle-callbacks>

		<id name="id" type="integer" column="id">
			<generator strategy="IDENTITY" />
		</id>
		<field name="name" column="name" type="string" length="50" nullable="true" unique="true" />
		<field name="email" column="email" type="string" column-definition="CHAR(32) NOT NULL" />
		<field name="isActive" column="is_active" type="boolean" />
	    <field name="login_count" type="integer" nullable="false">
	        <options>
	            <option name="comment">The number of times the user has logged in.</option>
	            <option name="default">0</option>
	        </options>
	    </field>		
		
		<one-to-one field="address" target-entity="Address" inversed-by="user">
			<cascade>
				<cascade-remove />
			</cascade>
			<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE" />
		</one-to-one>
<!-- 
		<one-to-many field="phonenumbers" target-entity="Foo\BarBundle\Entity\Phonenumber" mapped-by="user">
			<cascade>
				<cascade-persist />
			</cascade>
			<order-by>
				<order-by-field name="number" direction="ASC" />
			</order-by>
		</one-to-many>
		
        <many-to-many field="groups" target-entity="Foo\BarBundle\Entity\Group">
            <cascade>
                <cascade-all/>
            </cascade>
            <join-table name="users_groups">
                <join-columns>
                    <join-column name="user_id" referenced-column-name="id" nullable="false" unique="false" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="group_id" referenced-column-name="id" column-definition="INT NULL" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>
 -->        		

	</entity>
</doctrine-mapping>

 

## generate Entities from XML
$ php app/console doctrine:mapping:convert annotation ./src
## generate get//set method in Entity File
$ php app/console doctrine:generate:entities FooBarBundle
## update DB schema
$ php app/console doctrine:schema:update --force