<legend id='tt4tC'><style id='tt4tC'><dir id='tt4tC'><q id='tt4tC'></q></dir></style></legend>
    1. <small id='tt4tC'></small><noframes id='tt4tC'>

        <bdo id='tt4tC'></bdo><ul id='tt4tC'></ul>

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

        <i id='tt4tC'><tr id='tt4tC'><dt id='tt4tC'><q id='tt4tC'><span id='tt4tC'><b id='tt4tC'><form id='tt4tC'><ins id='tt4tC'></ins><ul id='tt4tC'></ul><sub id='tt4tC'></sub></form><legend id='tt4tC'></legend><bdo id='tt4tC'><pre id='tt4tC'><center id='tt4tC'></center></pre></bdo></b><th id='tt4tC'></th></span></q></dt></tr></i><div id='tt4tC'><tfoot id='tt4tC'></tfoot><dl id='tt4tC'><fieldset id='tt4tC'></fieldset></dl></div>
      2. 学说不允许 ResultSetMappingBuilder 工作

        时间:2023-08-19
      3. <small id='geVcU'></small><noframes id='geVcU'>

          <tfoot id='geVcU'></tfoot>
            <tbody id='geVcU'></tbody>
            <bdo id='geVcU'></bdo><ul id='geVcU'></ul>

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

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

                  本文介绍了学说不允许 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 问题,但我仍然遇到了修改后的 joinEntity 的遗留问题:

                  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 不太清楚,我不完全理解类 docblock 的描述.

                  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:

                  对于任何有同样问题的人来说,问题出在此行上发送的第 4 个参数上:

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

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

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

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

                  推荐答案

                  刚刚解决了这个问题:

                  对于任何有同样问题的人来说,问题出在此行上发送的第 4 个参数上:

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

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

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

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

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

                  上一篇:Symfony 2.3 Gedmo 学说扩展可翻译缓存 下一篇:如何在与 Doctrine 的多对多关系中避免重复条目?

                  相关文章

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

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

                      <bdo id='jPWmv'></bdo><ul id='jPWmv'></ul>
                    1. <small id='jPWmv'></small><noframes id='jPWmv'>