Syntax Error - line 0, col 469: Error: Expected known function, got 'IF'

Syntax Error - line 0, col 469: Error: Expected known function, got 'IF'

您好,我正在使用条令查询生成器来执行查询..

这是我的查询....

return $this->createQueryBuilder('sp')
                        ->select('sp.id, sp.price, sp.offer_price AS offerPrice, sp.price_kg AS PriceKg, '
                                . 'sp.offer_price_kg AS offerPriceKg, sp.status AS status, s.name AS storename')
                        ->addSelect("(CASE WHEN (sp.name IS NULL) THEN p.name ELSE sp.name END) AS spname")
                        ->addSelect("(CASE WHEN (sp.sku IS NULL) THEN p.sku ELSE sp.sku END) AS spsku")
                        ->addSelect("(CASE WHEN (sp.main_image IS NULL) THEN p.main_image ELSE sp.main_image END) AS sp_main_image")
                        ->join('sp.store', 's')
                        ->join('sp.product', 'p')
                        ->Where('IF(sp.name IS NULL, p.name, sp.name) LIKE :val')
                        ->orWhere('sp.sku LIKE :val')
                        ->setParameter('val', '%' . $search . '%')
                        ->getQuery();

如果条件出错,好像是这样,

->Where('IF(sp.name IS NULL, p.name, sp.name) LIKE :val')

这是我得到的错误,

[Syntax Error] line 0, col 469: Error: Expected known function, got 'IF'

反正你的语法很混乱,你为什么不这样做

->where('sp.name IS NULL AND p.name LIKE :val AND sp.name LIKE :val')

无论如何,Doctrine 没有内置的 "if" 功能,所以如果您需要一些特定的东西,您需要自己编程。

https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/cookbook/dql-user-defined-functions.html