【问题标题】:DQL findBy default queryDQL find默认查询
【发布时间】:2017-08-02 16:35:56
【问题描述】:

什么是 DQL findBy() 查询语法?

像这样: $this->getDoctrine()->getRepository("AppBundle:Users")->findBy($queryWhere);

【问题讨论】:

    标签: symfony doctrine dql


    【解决方案1】:

    它将为 WHERE CLAUSE 创建标准

    $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】:

    这通常与实体的属性一起使用。它需要一个数组,其中键作为实体上的属性名称,值作为您正在搜索的内容。

    例子:

    $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

    【讨论】:

    • Tnx 但我想知道像select u from ...这样的dql语法是什么
    猜你喜欢
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    相关资源
    最近更新 更多