Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine doesn't map fields from FOSUserBundle User class

I am using Symfony 2.1 RC1 and the FOSUserbundle on a Windows server running PHP 5.3.13.

I have followed the instructions here but Doctrine doesn't create fields in the database for the properties inherited from the base FOS User class (only the fields from my class).

Trying to login using the FOS login form produces the error:

Unrecognized field: usernameCanonical

I have the following Doctrine configuration:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

And the FOSUserBundle config looks like:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: SP\PickList\UserBundle\Entity\User

My User entity:

namespace SP\PickList\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Document\User as BaseUser;

/**
 * SP\PickList\UserBundle\Entity\User
 *
 * @ORM\Table(name="fos_user")
 * @ORM\Entity
 */
class User extends BaseUser
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
}

Thanks for any help,

James Bench

like image 261
jebbench Avatar asked Aug 21 '12 15:08

jebbench


3 Answers

It seems you are mixing instructions for ORM and ODM, if you use Doctrine ORM as per your config, your User class must extend FOS\UserBundle\Entity\User, try to change the use statement as

use FOS\UserBundle\Entity\User as BaseUser;
like image 180
mgiagnoni Avatar answered Oct 04 '22 16:10

mgiagnoni


To save someone some time. Don't forget if you are not using auto_mapping in your ORM config in config.yml you need to add 'FOSUserBundle: ~' to the mapping.

like image 37
someuser Avatar answered Oct 04 '22 16:10

someuser


Also you must specify which entity user class you'll use in app/config/config.yml

# FOS
fos-user: 
    db_driver: orm
    firewall_name: main #optional
    user_class: FOS\UserBundle\Entity\User
like image 36
Ali Emre Çakmakoğlu Avatar answered Oct 04 '22 17:10

Ali Emre Çakmakoğlu