0
votes

I have integrated FOS bundle in my project. Now, I want to allow multiple users with the same email, but FOS won't allow it.

How could I change the user implementation to allow that?

1
what email id? Give more information - Frank B
This might be a bad idea, because FOS assumes that the email is unique for certain functionalities (like password recovery). - Gerry
I know that, @Gerry, but my current project allows multiple user with same email, so I need to back-port this (horrible) functionality. - Alessandro Lai

1 Answers

1
votes

I had the same problem in my project. I solved it overriding some Doctrine definition on my User entity, that extends FOS' BaseUser.

I've done like this:

/**
 * @ORM\Entity()
 * @ORM\Table(name="user", uniqueConstraints={
 *   @ORM\UniqueConstraint(name="user_U_1", columns={"username"})
 * })
 * @ORM\AttributeOverrides({
 *     @ORM\AttributeOverride(name="emailCanonical",
 *         column=@ORM\Column(
 *             name="email_canonical",
 *             type="string",
 *             length=255,
 *             nullable=true,
 *             unique=false
 *         )
 *     ),
 *     @ORM\AttributeOverride(name="usernameCanonical",
 *         column=@ORM\Column(
 *             name="username_canonical",
 *             type="string",
 *             length=255,
 *             nullable=true,
 *             unique=false
 *         )
 *     )
 * })
 */
class User extends BaseUser
{
    [...]
}

The trick is done redefining the email_canonical field setting unique=false