将SQL转换为存储库中的docrine

时间:2018-10-08 11:42:26

标签: symfony doctrine-orm left-join

我有下一个sql:

SELECT * FROM `hex_articles_tree` tree 
LEFT JOIN hex_fields_i18n i18n 
ON i18n.tree_label_id = tree.id 
AND i18n.dos = 300
WHERE i18n.tree_label_id IS NOT NULL

我想学习如何将其转换为文档createQueryBuilder,我有我的symfony存储库:

namespace App\Repository;

use App\Entity\HexArticlesTree;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method HexArticlesTree|null find($id, $lockMode = null, $lockVersion = null)
 * @method HexArticlesTree|null findOneBy(array $criteria, array $orderBy = null)
 * @method HexArticlesTree[]    findAll()
 * @method HexArticlesTree[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class HexArticlesTreeRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, HexArticlesTree::class);
    }
}

如何在预览查询中添加功能?

感谢您的帮助


修改 我当前的代码如下:

return $this->createQueryBuilder('tree')
            ->select('tree')
            ->leftJoin('App\Entity\HexFieldsI18n', 'i18n', 'WITH','i18n.tree_label = tree.id')
            ->Where('i18n.dos=:dos')
            ->andWhere('i18n.tree_label IS NOT NULL')
            ->setParameter('dos', $dos)
            ->getQuery()->getResult();

0 个答案:

没有答案