BastienSander
BastienSander

Reputation: 1838

Doctrine2 FosUserBundle override column name

Using fosUserBundle in Symfony2 with Doctrine. Here are the versions :

Trying to override column name such as username one.

Here is what I do : namespace PROJECT\BUNDLE\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @ORM\Table(name="PROJECT_BUNDLE_USER")
 * @ORM\Entity(repositoryClass="PROJECT\BUNDLE\Entity\UserRepository")
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="username",
 *          column=@ORM\Column(
 *              name    = "BUNDLE_USERNAME"
 *          )
 *      ),
  [....]
 * })
 */
class User extends BaseUser
{
  [....]

When I want to generate the entity with php app/console doctrine:generate:entities PROJECT

   [Doctrine\ORM\Mapping\MappingException]                                             
      Invalid field override named 'username' for class 'PROJECT\BUNDLE\Entity\User'. 

EDIT 1 : add of namespace and use

EDIT 2 : Same error with type and length attributes fullfiled :

    column=@ORM\Column(
 *              name    = "USER_USERNAME",
 *              type    = "string",
 *              length  = 255
 *          )

Upvotes: 1

Views: 1392

Answers (2)

LamaDelRay
LamaDelRay

Reputation: 199

I spent all day on similar troubles, what worked for me to change a column name loaded is this :

/*
 * @ORM\Entity
 * @ORM\Table(name="Utilisateurs")
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="password",
 *         column=@ORM\Column(
 *             name="MDP",
 *             type="string",
 *             length=50,
 *             nullable=false
 *         )
 *     ),})

Where MDP is the name of my database_table and password the name FOSUserbundle wants. Be sure to have specified the type, for some reason everything go wrong without it. EDIT : This was done with FOSUserBundle ~1.3 , if you can downgrade it should work.

Upvotes: 2

Davi Koscianski Vidal
Davi Koscianski Vidal

Reputation: 193

Aren't you missing both column type and length?

Upvotes: 0

Related Questions