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

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

    1. <tfoot id='OBPss'></tfoot>

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

      不允许 ResultSetMappingBuilder 工作的原则

      时间:2024-08-09

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

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

      <tfoot id='rQOPM'></tfoot>
        <legend id='rQOPM'><style id='rQOPM'><dir id='rQOPM'><q id='rQOPM'></q></dir></style></legend>

          <tbody id='rQOPM'></tbody>

              • <bdo id='rQOPM'></bdo><ul id='rQOPM'></ul>
              • 本文介绍了不允许 ResultSetMappingBuilder 工作的原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我将 Symfony 2 与教义一起使用.我已经建立了一个具有自定义查找功能的自定义存储库.当它加入子查询时,我很确定从我所读到的内容中,我需要使用 ResultSetMappingBuilder 从查询中获取结果.但我不断收到以下错误:

                I'm using Symfony 2 with doctrine. I've set up a custom repository with a custom find function. As it joins to a subquery I'm pretty sure from what I've read that I'll need to use the ResultSetMappingBuilder to get the results back from the query. But I keep getting the following error:

                The column 'id' conflicts with another column in the mapper. 
                

                我的代码是:

                    $sql ="SELECT c.id as cid, c.country, c.rank, c.continent, q.*
                        FROM country c
                        INNER JOIN (
                            SELECT d.* , MAX( d.rating ) AS maxrating
                            FROM ducks d
                            GROUP BY d.country_id
                        )q ON ( q.country_id = c.id )";
                
                    $rsm = new DoctrineORMQueryResultSetMappingBuilder($this->getEntityManager());
                    $rsm->addRootEntityFromClassMetadata('WfukDuckBundleEntityCountry', 'c', array('id' => 'cid'));
                    $rsm->addJoinedEntityFromClassMetadata('WfukDuckBundleEntityDucks', 'ducks', 'c', 'country_id');
                
                    $query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
                    return $query->getResult();
                

                SQL 查询自行运行,没有任何问题,并返回我期望的结果.

                The SQL query runs on it's own without any problems and returns the results I'd expect.

                更新,我已经通过重新映射 addRootEntityFromClassMetadata 上的 id 字段解决了 id 问题,但修改后的joinedEntity 仍然存在问题:

                UPDATE, I've fixed the id issue by remapping the id field on the addRootEntityFromClassMetadata, but I've still got a remaining problem with the revised joinedEntity:

                    $rsm->addJoinedEntityFromClassMetadata('WfukDuckBundleEntityDucks', 'ducks', 'c', 'country_id');
                

                我收到以下错误:

                Notice: Undefined index: country_id in E:DocumentswfukWorkduck travelswampvendordoctrinelibDoctrineORMInternalHydrationObjectHydrator.php line 85 
                

                我很确定这是调用中的最后一个值 country_id,但我不能 100% 确定这是什么.这里的解释:http://readthedocs.org/docs/doctrine-orm/en/latest/reference/native-sql.html 不太清楚,我不完全理解类文档块的描述.

                I'm pretty sure this is down to the last value in the call, country_id, but I'm not 100% sure what this is. The explanation here: http://readthedocs.org/docs/doctrine-orm/en/latest/reference/native-sql.html isn't too clear and I don't fully understand the description from the class docblock.

                它给出的错误是:

                The error it gives is:

                The column 'id' conflicts with another column in the mapper. 
                

                但我已为其中一个结果重命名了 id 字段,因此结果集只有一列称为id".

                Yet I have renamed the id field for one of the results so the result set only has one column called 'id'.

                错误的堆栈跟踪显示它被抛出这里:

                The stacktrace on the error shows it's being thrown here:

                at ResultSetMappingBuilder ->addAllClassFields ('WfukDuckBundleEntityDucks', 'q', array())
                in E:DocumentswfukWorkduck travelswampvendordoctrinelibDoctrineORMQueryResultSetMappingBuilder.php at line 71
                

                我怀疑这很明显,但是我可以在任何地方找到有关此功能的文档方式并不多...

                I suspect it's something obvious but there's not much in the way of documentation on this function that I could find anywhere...

                已解决:

                我不能在另外 5 小时内将其添加为答案,因此为避免任何人浪费时间回答此问题,答案是:

                I can't add this as an answer for another 5 hours, so to avoid anyone wasting time answering this the answer is:

                对于任何有同样问题的人,问题出在这一行发送的第四个参数:

                For anyone who has the same problem the problem was with the 4th parameter sent on this line:

                $rsm->addJoinedEntityFromClassMetadata('WfukDuckBundleEntityDucks', 'ducks', 'c', 'ducks');
                

                这应该包含 Country 类中的字段,我用来在其中存储鸭子的 arrayCollection.

                Which should have held the field within the Country class that I was using to store the arrayCollection of ducks within it.

                推荐答案

                在问题解决后结束:

                对于任何有同样问题的人,问题出在这一行发送的第四个参数:

                For anyone who has the same problem the problem was with the 4th parameter sent on this line:

                $rsm->addJoinedEntityFromClassMetadata('WfukDuckBundleEntityDucks', 'ducks', 'c', 'ducks');
                

                这应该包含 Country 类中的字段,我用来在其中存储鸭子的 arrayCollection.

                Which should have held the field within the Country class that I was using to store the arrayCollection of ducks within it.

                这篇关于不允许 ResultSetMappingBuilder 工作的原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <tfoot id='AfEQf'></tfoot>

                      <i id='AfEQf'><tr id='AfEQf'><dt id='AfEQf'><q id='AfEQf'><span id='AfEQf'><b id='AfEQf'><form id='AfEQf'><ins id='AfEQf'></ins><ul id='AfEQf'></ul><sub id='AfEQf'></sub></form><legend id='AfEQf'></legend><bdo id='AfEQf'><pre id='AfEQf'><center id='AfEQf'></center></pre></bdo></b><th id='AfEQf'></th></span></q></dt></tr></i><div id='AfEQf'><tfoot id='AfEQf'></tfoot><dl id='AfEQf'><fieldset id='AfEQf'></fieldset></dl></div>
                        <tbody id='AfEQf'></tbody>
                      <legend id='AfEQf'><style id='AfEQf'><dir id='AfEQf'><q id='AfEQf'></q></dir></style></legend>
                        <bdo id='AfEQf'></bdo><ul id='AfEQf'></ul>
                      • <small id='AfEQf'></small><noframes id='AfEQf'>