在与ManyToMany相关的两个实体中,根据此链接https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/working-with-objects.html,可以通过引用第二个实体进行搜索。 这是我的示例:
UsuariosBundle\Entity\Users:
type: entity
table: null
repositoryClass: UsuariosBundle\Repository\UsersRepository
manyToMany:
espec:
targetEntity: UsuariosBundle\Entity\Especialidad
inversedBy: users
joinTable:
name: fos_user_espec
joinColumns:
user_id:
referencedColumnName: id
inverseJoinColumns:
espc_id:
referencedColumnName: id
grupos:
targetEntity: UsuariosBundle\Entity\Grupo
joinTable:
name: fos_user_grupo
joinColumns:
user_id:
referencedColumnName: id
inverseJoinColumns:
group_id:
referencedColumnName: id
oneToMany:
soli:
targetEntity: SolicitudeBundle\Entity\Solicitudes
mappedBy: user_creador
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 50
last_name:
type: string
length: 100
foto:
type: string
length: 100
nullable: TRUE
lifecycleCallbacks: { }
UsuariosBundle\Entity\Grupo:
type: entity
table: null
repositoryClass: UsuariosBundle\Repository\RolesRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
lifecycleCallbacks: { }
fields:
name:
type: string
length: 50
$grupo = $this->getDoctrine()
->getRepository(Users::class)
->findByGrupos(1);
错误:
SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'fos_user_grupo.group_id' 谢谢!