Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite an Entity in Symfony2 bundle

I'm using FOSUserBundle for Symfony2, and I need to be able to register a user without validating if the email is Unique, I just need a valid email so many users can have the same email ( I know this is weird, but I need it).

I have an entity "User" in a bundle that extends FOSUserBundle, is it possible to overwrite the column definition of emailCanonical to eliminate the unique parameter and remove the validation from the FormType?

I'm using Annotation for mapping my Entities and YML for validation of my forms.

like image 698
dturcotte Avatar asked Sep 19 '11 19:09

dturcotte


People also ask

How to override bundle Symfony?

The easiest way to "override" a bundle's routing is to never import it at all. Instead of importing a third-party bundle's routing, copy that routing file into your application, modify it, and import it instead.

What is a bundle in Symfony?

A Symfony bundle is a collection of files and folders organized in a specific structure. The bundles are modeled in such a way that it can be reused in multiple applications. The main application itself is packaged as a bundle and it is generally called AppBundle.


1 Answers

I had a similar issue few weeks ago. The only solution is to extend model instead of entity:

use FOS\UserBundle\Model\User as BaseUser;

class User extends BaseUser

The downside is that you have to also copy everything from FOS User entity to your User entity. On the other hand, you can adjust the functionality to your needs.

like image 154
Ondrej Slinták Avatar answered Sep 18 '22 13:09

Ondrej Slinták