I cannot authenticate to symfony2 using the Employee object, because it contains many mappings with other objects in my project. Some of my mappings are as follows:
/**
* @var EmployeeDesignation
*
* @ORM\ManyToOne(targetEntity="EmployeeDesignation")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="employee_designation_id", referencedColumnName="id")
* })
*/
private $employeeDesignation;
/**
* @var EmployeeDesignation
*
* @ORM\ManyToOne(targetEntity="EmployeeType")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="employee_type_id", referencedColumnName="id")
* })
*/
private $employeeType;
Authentication works fine without any mapping. I tried using the Serialize () and 'Unserialize ()' methods as shown below:
class Employee implements AdvancedUserInterface, \Serializable{
public function serialize() {
return serialize($this->emailOfficial);
}
public function unserialize($data) {
$this->em = unserialize($data);
}
After executing the above method, I get the following error:
You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.
I tried this way to get rid of the previous error, which looks like this:
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL
So, can anyone suggest a way to overcome this problem?
source
share