使用Doctrine Query Builder转换SQL查询

时间:2019-05-21 13:04:56

标签: php sql symfony doctrine left-join

SQL-是正确的,可以在mysql-console中使用。我有一些SQL查询,可用于从数据库产品中进行选择。我只是尝试将其放入存储库中,但根本没有用。

这也是ProductRepository的功能代码

有人可以帮我还是显示我的错误,并解释如何将SQL转换为查询生成器查询或强制使用纯SQL?

SELECT *
FROM accounting_products
LEFT JOIN accounting_incoming_invoice_items 
    ON accounting_incoming_invoice_items.product_id = accounting_products.id
WHERE accounting_incoming_invoice_items.outcome_price >
          accounting_incoming_invoice_items.price;
    public function findAllOnStorage()
    {
        $rsm = new ResultSetMapping($this->getEntityManager());

        $query = $this->getEntityManager()->createNativeQuery(
            "SELECT * FROM accounting_products LEFT JOIN accounting_incoming_invoice_items 
                    ON accounting_incoming_invoice_items.product_id = accounting_products.id
                    WHERE accounting_incoming_invoice_items.outcome_price > accounting_incoming_invoice_items.price;",
            $rsm);

        $all = $query->getResult();
        #dump($all);exit;
        return $all;
    }

如果在存储库中使用纯SQL-则行不通。查询结果为空集,但在控制台中,它仅返回一条记录

尝试将SQL转换为查询生成器没有成功。

1 个答案:

答案 0 :(得分:0)

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE a1_.outcome_price > a1_.price' at line 1

但是MariaDB仍然抛出错误:

{{1}}