I am trying to override two properties of FOSUserBundle's User mapping.
use FOS\UserBundle\Model\User as BaseUser;
...
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="user")
* @UniqueEntity(
* fields={"emailCanonical", "zone"},
* errorPath="email",
* message="This email address is already in use."
* )
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=false)),
* @ORM\AttributeOverride(name="emailCanonical", column=@ORM\Column(type="string", name="emailCanonical", length=255, unique=false, nullable=false))
* })
*/
class User extends BaseUser
{
...
Everything seems to be working fine, except when I generate accessors: Invalid field override named 'email'
The error is thrown here:
// Doctrine\ORM\Mapping\ClassMetadataInfo
public function setAttributeOverride($fieldName, array $overrideMapping)
{
if ( ! isset($this->fieldMappings[$fieldName])) {
throw MappingException::invalidOverrideFieldName($this->name, $fieldName);
}
Here, $this->fieldMappings
only contains the fields of my child User and not of the parent (mapped superclass).
Anyone got a clue?
The way I managed to fix this issue with Invalid field override named [field] for class [class] was to also add the overwritten attribute in the class I overwritten it.
I'm using version Symfony v2.7.8 and Doctrine v1.6.1.
Example:
<?php
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*
* @ORM\HasLifecycleCallbacks
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="usernameCanonical",
* column=@ORM\Column(
* type="string",
* name="username_canonical",
* length=255,
* unique=false
* )
* )
* })
*/
class User extends BaseUser
{
/**
* @var string
*
* @ORM\Column(type="string", name="username_canonical", length=255, unique=false)
*/
protected $usernameCanonical;
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With