1. <legend id='2Wdir'><style id='2Wdir'><dir id='2Wdir'><q id='2Wdir'></q></dir></style></legend>

      • <bdo id='2Wdir'></bdo><ul id='2Wdir'></ul>

      <i id='2Wdir'><tr id='2Wdir'><dt id='2Wdir'><q id='2Wdir'><span id='2Wdir'><b id='2Wdir'><form id='2Wdir'><ins id='2Wdir'></ins><ul id='2Wdir'></ul><sub id='2Wdir'></sub></form><legend id='2Wdir'></legend><bdo id='2Wdir'><pre id='2Wdir'><center id='2Wdir'></center></pre></bdo></b><th id='2Wdir'></th></span></q></dt></tr></i><div id='2Wdir'><tfoot id='2Wdir'></tfoot><dl id='2Wdir'><fieldset id='2Wdir'></fieldset></dl></div>

      <small id='2Wdir'></small><noframes id='2Wdir'>

      <tfoot id='2Wdir'></tfoot>

      Doctrine 2 mysql FIELD 函数按顺序由

      时间:2023-06-01
    1. <legend id='F1B0i'><style id='F1B0i'><dir id='F1B0i'><q id='F1B0i'></q></dir></style></legend>
        <bdo id='F1B0i'></bdo><ul id='F1B0i'></ul>
        <tfoot id='F1B0i'></tfoot>
                  <tbody id='F1B0i'></tbody>

                <small id='F1B0i'></small><noframes id='F1B0i'>

              1. <i id='F1B0i'><tr id='F1B0i'><dt id='F1B0i'><q id='F1B0i'><span id='F1B0i'><b id='F1B0i'><form id='F1B0i'><ins id='F1B0i'></ins><ul id='F1B0i'></ul><sub id='F1B0i'></sub></form><legend id='F1B0i'></legend><bdo id='F1B0i'><pre id='F1B0i'><center id='F1B0i'></center></pre></bdo></b><th id='F1B0i'></th></span></q></dt></tr></i><div id='F1B0i'><tfoot id='F1B0i'></tfoot><dl id='F1B0i'><fieldset id='F1B0i'></fieldset></dl></div>
                本文介绍了Doctrine 2 mysql FIELD 函数按顺序由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试在查询的 order by 子句中使用 MySQL FIELD 函数.我假设 Doctrine 2 不支持开箱即用的 FIELD 功能 - 这是真的吗?如果是这样,我该如何使用它?我是否必须将整个查询转换为本地查询?是否有添加此功能的 Doctrine 2 扩展?

                I'm trying to use the MySQL FIELD function in an order by clause in a query. I'm assuming that Doctrine 2 doesn't support the FIELD function out of the box - is that true? If so, how can I use it? Will I have to turn my whole query into a native query? Is there a Doctrine 2 extension that adds this functionality?

                推荐答案

                Jeremy Hicks,感谢 您的扩展程序.我不知道如何将您的职能与教义联系起来,但最终我找到了答案.

                Jeremy Hicks, thanks for your extension. I didn`t know how to connect your function to doctrine, but finally i find answer.

                $doctrineConfig = $this->em->getConfiguration();
                $doctrineConfig->addCustomStringFunction('FIELD', 'DoctrineExtensions\Query\Mysql\Field');
                

                我需要 FIELD 函数来对我通过 IN 表达式选择的实体进行排序.但是您只能在SELECT, WHERE, BETWEEN 子句中使用此函数,而不能在ORDER BY 中使用.

                I need FIELD function to order my Entities that i select by IN expression. But you can use this function only in SELECT, WHERE, BETWEEN clause, not in ORDER BY.

                解决方案:

                $qb
                            ->select("r, field(r.id, " . implode(", ", $ids) . ") as HIDDEN field")
                            ->from("Entities\Round", "r")
                            ->where($qb->expr()->in("r.id", $ids))
                            ->orderBy("field");
                

                为了避免在结果行中添加 field 别名,您需要放置 HIDDEN 关键字.所以这是如何能够在 Doctrine 2.2 中的 IN 表达式中对值进行排序.

                To avoid adding field alias into your result row you need put HIDDEN keyword. So this how to be able order values in IN expression in Doctrine 2.2.

                这篇关于Doctrine 2 mysql FIELD 函数按顺序由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:SQL SELECT 获取前 N 个正整数 下一篇:这两种连接表方法之间的区别?

                相关文章

                • <bdo id='pMLbe'></bdo><ul id='pMLbe'></ul>

                <i id='pMLbe'><tr id='pMLbe'><dt id='pMLbe'><q id='pMLbe'><span id='pMLbe'><b id='pMLbe'><form id='pMLbe'><ins id='pMLbe'></ins><ul id='pMLbe'></ul><sub id='pMLbe'></sub></form><legend id='pMLbe'></legend><bdo id='pMLbe'><pre id='pMLbe'><center id='pMLbe'></center></pre></bdo></b><th id='pMLbe'></th></span></q></dt></tr></i><div id='pMLbe'><tfoot id='pMLbe'></tfoot><dl id='pMLbe'><fieldset id='pMLbe'></fieldset></dl></div>
                <tfoot id='pMLbe'></tfoot>

                    <legend id='pMLbe'><style id='pMLbe'><dir id='pMLbe'><q id='pMLbe'></q></dir></style></legend>

                    <small id='pMLbe'></small><noframes id='pMLbe'>