Issue: Doctrine\ORM\Query\QueryException
Semantical Error] line 0, col 45 near 'roles IN(:ro': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.
Caused By:
$qb->select('u')
->from(\Eho\Core\Entity\User::class,'u')
->where($qb->expr()->in('u.roles',':roleTypes'))
->setParameter('roleType', $roleTypes);
Where $roleTypes = Object \App\Entity\Role::class (tested both singular and array of)
Structure and ENV
- Entities: User, Roles
- Tables: user, roles, user_roles
Relationship on Entity User:
class User {
:
@ORM\ManyToMany(targetEntity="\App\User\Entity\Role")
@ORM\JoinTable(name="user_role",
joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
)
private $roles;
I've tried several methods (em->findByRoles($role) , $em->findByRoles([$roles]); which produces:
An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_role.role_id' in 'where clause'
The column is on the table user_roles
CREATE TABLE
user_role(idint(11) UNSIGNED NOT NULL,
user_idint(11) UNSIGNED NOT NULL,role_idint(11) UNSIGNED NOT NULL )