代码之家  ›  专栏  ›  技术社区  ›  A.Seddighi

DQL通过默认查询查找

  •  1
  • A.Seddighi  · 技术社区  · 7 年前

    findBy()

    $this->getDoctrine()->getRepository(“AppBundle:Users”)->findBy($queryWhere);

    2 回复  |  直到 7 年前
        1
  •  0
  •   Serghei Luchianenco    7 年前

    它将为WHERE子句创建标准

    $repository->findBy(['email' => 'test@test.com', 'city' => 'Berlin'])
    
    SELECT * FROM table WHERE email = "test@test.com" AND city = "Berlin"
    

    getSelectSQL 在以下链接下

    http://www.doctrine-project.org/api/orm/2.5/source-class-Doctrine.ORM.Persisters.Entity.BasicEntityPersister.html#877-891

        2
  •  0
  •   Ollie in PGH    7 年前

    这通常与实体的属性一起使用。它接受一个数组,其中键作为实体上的属性名,值作为搜索的内容。

    $this->getDoctrine()
        ->getRepository('AppBundle:Users')
        ->findBy(['id' => $id])
    ;
    
    $this->getDoctrine()
       ->getRepository('AppBundle:Users')
       ->findBy(['userName' => $userName])
    ;
    
    $this->getDoctrine()
       ->getRepository('AppBundle:Users')
       ->findBy(['email' => $email])
    ;
    

    您可以在此处阅读更多信息: https://symfony.com/doc/current/doctrine.html#fetching-objects-from-the-database