Answer the question
In order to leave comments, you need to log in
Why does User (sf3) always return only one role?
I understand with sf3. The problem is that during (custom) authentication, the user selects only one role, the first one found in the database. I look at the profiler - the request for obtaining roles from the database is not limited by the number of lines.
User entity:
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User implements UserInterface, \Serializable
{
// ...
/**
* @ORM\OneToMany(targetEntity="Role", mappedBy="user")
*/
private $roles;
public function __construct()
{
$this->roles = new ArrayCollection();
}
public function getRoles()
{
return $this->roles->toArray();
}
// ...
}
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\Role\Role as BaseRole;
/**
* @ORM\Entity
* @ORM\Table(name="users_role")
*/
class Role extends BaseRole
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="User", inversedBy="roles")
*/
private $user;
/**
* @ORM\Column(type="string", length=30)
*/
protected $role;
// ...
}
Answer the question
In order to leave comments, you need to log in
Offhand, I can assume that the problem is in the Role entity, you have the Id annotation in $user. This means that you must have a unique user_id for each entry. So I can’t even imagine how you managed to assign 2 roles for 1 user, if this database should not roll around for you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question