FOSUserBundle
FOSUserBundle copied to clipboard
Replacing the mapping
I need to replace the mapping of the user entity because I need to use a legacy database. So I created a User class which extends FOS\UserBundle\Model\User and declares its own mapping (using annotations) as explained in "Replacing the mapping of the bundle" https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/doctrine.md
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Serializable;
/**
* @ORM\Entity(repositoryClass="UserRepository")
* @ORM\Table
*/
class User extends BaseUser implements AdvancedUserInterface, EquatableInterface, Serializable {
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="login", type="string", length=50)
*/
protected $login;
/**
* @ORM\Column(name="paswd", type="string", length=100)
*/
protected $password;
// ....
}
But it seems that Doctrine sees both mappings and it throws this error:
Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Property "password" in "MPG\AuthenticacionBundle\Entity\User" was already declared, but it must be declared only once' in /var/www/mpg/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:238
Do I need to add something else for this to work?
I think is related with https://github.com/FriendsOfSymfony/FOSUserBundle/pull/1081#issuecomment-19027818
@laherreria the right solution is in comments of #982 (ndlr use attribute override)
This is pretty annoying. Is this a problem with Doctrine changing mapping rules and introducing AttributeOverride and AssociationOverride or this is FOSUserBundle.
I have the same problem trying to override 'roles' as I handle this via ManyToMany and can not use AssociationOverride as there is no such syntax to define ManyToMany there.
/**
* @ORM\ManyToMany(targetEntity="Role", indexBy="name", cascade={"persist"}, fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="app_users_roles")
*/
protected $roles;
Shouldn't we have a TAG with version available for the old approach? (allowing overrides)?
@rat4m3n you got any solution to this? I am trying to do same thing
My solution to this was not to inherit anything and define my User object without extending FOSModel at all.
I am in the same situation. Did you find a solution ? (an other rather than inheriting anything). Thank you.
Why don't we refactor FOSUserBundle to use the EasyExtends feature from Sonata-project ? https://sonata-project.org/bundles/easy-extends/master/doc/reference/why.html
I found this to be a far easier solution that also works with MongoDB:
http://blog.lavoie.sl/2015/01/symfony-override-doctrine-mapping.html