Adding extra fields to FOSUserBundle / SonataUserBundle

Sadly, this isn’t really documented (at time of writing).

Adding new protected variables to your User.php entity will not actually create database entries when you try to do a doctrine:schema:update.

While one still needs to have the protected variables in this entity class, along with getters and setters, the actual creation work is within UserBundle/Resources/config/doctrine/User.orm.xml

Here is an example for adding a foreign key:

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns=""

    <entity name="Application\Sonata\UserBundle\Entity\User" table="fos_user_user">

        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />

        <many-to-one field="client" target-entity="Myvendor\MyBundle\Entity\Client" orphan-removal="">
                <join-column name="client_id" referenced-column-name="id" nullable="1"/>


You can leave a response, or trackback from your own site.

2 Responses to “Adding extra fields to FOSUserBundle / SonataUserBundle”

  1. valqk says:

    A year later it’s still not documented.
    Thanks man :)

  2. Daniel says:

    Thanx, I couldn’t find this info anywhere… except here :)

Leave a Reply