Doppeltes Join - Unknown Column

  • fuzz fuzz
    Jedi-Meister
    0 x
    291 Beiträge
    5 Hilfreiche Beiträge
    13. 02. 2013, 14:46

    Hallo,

    muss in meinem Repository an zwei stellen schauen ob ein Institut aus einem bestimmten Land kommt. Das habe ich wie folgt versucht:

    1. $query->logicalOr( $query->equals('coordinatingInstitute.country.uid',(integer)$sterm['country']),
    2. $query->equals('institutes.country.uid',(integer)$sterm['country'])
    3. )

    Das führt jedoch zu einer Exception mit folgender Meldung:

    1. #1247602160: UNKNOWN COLUMN 'tx_nnctcp_project_institute_mm.uid_foreign' IN 'on clause': SELECT DISTINCT tx_nnctcp_domain_model_project.* FRO...

    Lasse ich eine "Equals" Abfrage von beiden weg, funktioniert alles wunderbar.

    Mache ich was falsch oder wie kann ich das lösen?

    TypoScript kann alles, auch kochen! ...Man muss nur wissen wie ;-)

    Take a look at my TYPO3 Extensions in the Repository:
    content_designer, k23_imagecrop, nn_address and more...


  • 1

  • 0 x
    13. 02. 2013, 15:32

    Du hast nicht die ganze Query gepostet und ich kenne dein TCA / Models und Tables nicht, aber 'tx_nnctcp_project_institute_mm.uid_foreign' dürfte ein Feld in einer Standard TYPO3 MM Tabelle sein. D.h. du hast wahrscheinlich im TCA eine MM Tabelle konfiguriert (tx_nnctcp_project_institute_mm). Existiert diese? Wenn ja sollte sie auch ein uid_foreign Feld haben...

  • fuzz fuzz
    Jedi-Meister
    0 x
    291 Beiträge
    5 Hilfreiche Beiträge
    13. 02. 2013, 15:37

    Hallo,

    danke erstmal für die fixe antwort...

    ja die Tabelle existiert und wenn ich nur ein Equals hinzufüge (anstatt wie im beispiel zwei) geht es. Es geht nicht wenn 2 unterschiedliche Felder (Institutes und CoordinatingInstitute) auf die selbe M:N Tabelle zugreifen wollen, dann macht extbase zweimal einen JOIN auf ein und die selbe Tabelle womit mysql wohl nicht klar kommt.

    hier die ganze query / fehlermeldung...

    1. #1247602160: UNKNOWN COLUMN 'tx_nnctcp_project_institute_mm.uid_foreign' IN 'on clause':
    2. SELECT DISTINCT tx_nnctcp_domain_model_project.* FROM tx_nnctcp_domain_model_project LEFT JOIN tx_nnctcp_domain_model_institute ON tx_nnctcp_project_institute_mm.uid_foreign=tx_nnctcp_domain_model_institute.uid LEFT JOIN tx_nnctcp_domain_model_country ON tx_nnctcp_domain_model_institute.country=tx_nnctcp_domain_model_country.uid LEFT JOIN tx_nnctcp_project_institute_mm ON tx_nnctcp_domain_model_project.uid=tx_nnctcp_project_institute_mm.uid_local WHERE ((tx_nnctcp_domain_model_project.pid IN ('73') AND tx_nnctcp_domain_model_project.refid LIKE '%1225%') AND (tx_nnctcp_domain_model_country.uid = '5' OR tx_nnctcp_domain_model_country.uid = '5')) AND tx_nnctcp_domain_model_project.deleted=0 AND tx_nnctcp_domain_model_project.t3ver_state<=0 AND tx_nnctcp_domain_model_project.pid<>-1 AND tx_nnctcp_domain_model_project.hidden=0 AND tx_nnctcp_domain_model_project.starttime<=1360766220 AND (tx_nnctcp_domain_model_project.endtime=0 OR tx_nnctcp_domain_model_project.endtime>1360766220) AND tx_nnctcp_domain_model_project.sys_language_uid IN (0,-1) AND tx_nnctcp_domain_model_project.pid IN (73, 77, 78-) AND tx_nnctcp_domain_model_institute.deleted=0 AND tx_nnctcp_domain_model_institute.t3ver_state<=0 AND tx_nnctcp_domain_model_institute.pid<>-1 AND tx_nnctcp_domain_model_institute.hidden=0 AND tx_nnctcp_domain_model_institute.starttime<=1360766220 AND (tx_nnctcp_domain_model_institute.endtime=0 OR tx_nnctcp_domain_model_institute.endtime>1360766220) AND tx_nnctcp_domain_model_institute.sys_language_uid IN (0,-1) AND tx_nnctcp_domain_model_institute.pid IN (73, 77, 78-) AND tx_nnctcp_domain_model_country.deleted=0 AND tx_nnctcp_domain_model_country.t3ver_state<=0 AND tx_nnctcp_domain_model_country.pid<>-1 AND tx_nnctcp_domain_model_country.hidden=0 AND tx_nnctcp_domain_model_country.starttime<=1360766220 AND (tx_nnctcp_domain_model_country.endtime=0 OR tx_nnctcp_domain_model_country.endtime>1360766220) AND tx_nnctcp_domain_model_country.sys_language_uid IN (0,-1) AND tx_nnctcp_domain_model_country.pid IN (73, 77, 78-) ORDER BY tx_nnctcp_domain_model_project.refid ASC (More information)
    3.  
    4. Tx_Extbase_Persistence_Storage_Exception_SqlError thrown IN file
    5. C:\TYPO3\4.7.0\htdocs\Introduction\typo3\sysext\extbase\Classes\Persistence\Storage\Typo3DbBackend.php IN line 1020.

    TypoScript kann alles, auch kochen! ...Man muss nur wissen wie ;-)

    Take a look at my TYPO3 Extensions in the Repository:
    content_designer, k23_imagecrop, nn_address and more...


  • 0 x
    13. 02. 2013, 15:49

    Ja ich seh schon, das ist dann wohl ein Problem im QueryBuilder von Extbase. Da wird auf die mm Tabelle gematched bevor die überhaupt gejoined wurde...

    Probier doch bitte mal testweise diese Query mit dieser Veränderung:

    ORIGINAL:

    1. SELECT DISTINCT tx_nnctcp_domain_model_project.* FROM tx_nnctcp_domain_model_project LEFT JOIN tx_nnctcp_domain_model_institute ON tx_nnctcp_project_institute_mm.uid_foreign=tx_nnctcp_domain_model_institute.uid LEFT JOIN tx_nnctcp_domain_model_country ON tx_nnctcp_domain_model_institute.country=tx_nnctcp_domain_model_country.uid LEFT JOIN tx_nnctcp_project_institute_mm ON tx_nnctcp_domain_model_project.uid=tx_nnctcp_project_institute_mm.uid_local WHERE HIER KOMMEN DIE GANZEN WHERE BEDINGUNGEN....

    GEÄNDERT:

    1. SELECT DISTINCT tx_nnctcp_domain_model_project.* FROM tx_nnctcp_domain_model_project LEFT JOIN tx_nnctcp_project_institute_mm ON tx_nnctcp_domain_model_project.uid=tx_nnctcp_project_institute_mm.uid_local LEFT JOIN tx_nnctcp_domain_model_institute ON tx_nnctcp_project_institute_mm.uid_foreign=tx_nnctcp_domain_model_institute.uid LEFT JOIN tx_nnctcp_domain_model_country ON tx_nnctcp_domain_model_institute.country=tx_nnctcp_domain_model_country.uid WHERE HIER KOMMEN DIE GANZEN WHERE BEDINGUNGEN....

    Wahrscheinlich funktioniert es dann auch noch nicht, aber sieht zumindest realistischer aus ;)

  • fuzz fuzz
    Jedi-Meister
    0 x
    291 Beiträge
    5 Hilfreiche Beiträge
    13. 02. 2013, 16:00

    Hui, also ein Bug in extbase?
    Gibt es dafür irgendwie einen patch oder so?

    Also der Query funktioniert, jedoch liefert er 0 datensätze zurück obwohl mindestens 1 erscheinen würde.

    Ich werd mir da schon einen query zusammen bauen können der klappt, aber lieber würde ich natürlich die extbase funktionen nutzen anstatt ein eigenes sql statement zu schreiben.

    TypoScript kann alles, auch kochen! ...Man muss nur wissen wie ;-)

    Take a look at my TYPO3 Extensions in the Repository:
    content_designer, k23_imagecrop, nn_address and more...


  • 0 x
    13. 02. 2013, 16:10

    Joa, ich würde sagen das sieht nach Extbase Bug aus, da ich den Bug bisher nicht kannte, kann ich auch nichts über eventuelle Patches sagen. Guck am besten mal in review.typo3.org ob da was zu finden ist.

  • beo6 beo6
    Padawan
    0 x
    45 Beiträge
    1 Hilfreiche Beiträge
    13. 02. 2013, 17:51

    Ich bin mir nicht ganz sicher.

    Aber müsste das nicht mit "$query->matching();" gekapselt werden?

    Dann müsste es so aussehen:

    1. <?php
    2. $query = $this->createQuery();
    3.  
    4. $query->matching(
    5. $query->logicalOr(
    6. $query->equals('coordinatingInstitute.country.uid',(integer)$sterm['country']),
    7. $query->equals('institutes.country.uid',(integer)$sterm['country'])
    8. )
    9. );
    10.  
    11. return $query->execute();


  • 0 x
    13. 02. 2013, 20:20

    Davon ging ich jetzt sowieso aus, sonst würde man eine Fehlermeldung und gar keine Query bekommen.

  • fuzz fuzz
    Jedi-Meister
    0 x
    291 Beiträge
    5 Hilfreiche Beiträge
    14. 02. 2013, 09:21

    Moin,

    also in dem Tracker habe ich nichts passendes gefunden... war mir aber auch nicht 100%ig sicher nach was ich gucken soll.

    Jedenfalls habe ich den Query mal etwas aufgebohrt. Mein Thema "Doppeltes Join" ist auch etwas fehl. Die Reihenfolge der Joins ist fehlerhaft. Wenn ich diese umdrehe gibt es zumindest keine Fehler mehr...

    Jetzt habe ich aber das Problem das 0 Ergebnisse geliefert werden anstatt 1. Das kommt weil das Feld "coordinatingInstitute" aus der Projects Tabelle nicht berücksichtigt wird.

    Was mache ich falsch bzw. kann wie kann ich das lösen? Idealerweise über das Extbase Query Object... [b]Denn vielleicht baue ich da ja schon den Query falsch zusammen der dann den "Bug" verursacht?[/b]

    Hier mal der Query mit den Joins in der korrekten Reihenfolge (aber 0 ergebnisse) und mein Extbase Query Aufruf (welche den fehlerhaften query) produziert.

    1. SELECT DISTINCT tx_nnctcp_domain_model_project.*
    2.  
    3. FROM tx_nnctcp_domain_model_project
    4.  
    5. LEFT JOIN tx_nnctcp_project_institute_mm
    6. ON tx_nnctcp_domain_model_project.uid = tx_nnctcp_project_institute_mm.uid_local
    7.  
    8. LEFT JOIN tx_nnctcp_domain_model_institute
    9. ON tx_nnctcp_project_institute_mm.uid_foreign = tx_nnctcp_domain_model_institute.uid
    10.  
    11. LEFT JOIN tx_nnctcp_domain_model_country
    12. ON tx_nnctcp_domain_model_institute.country = tx_nnctcp_domain_model_country.uid
    13.  
    14. WHERE (
    15.  
    16. (
    17. tx_nnctcp_domain_model_project.pid IN ('73')
    18. AND
    19. tx_nnctcp_domain_model_project.refid LIKE '%1225%'
    20. )
    21.  
    22. AND tx_nnctcp_domain_model_country.uid = '5'
    23. )
    24.  
    25. AND tx_nnctcp_domain_model_project.deleted = 0
    26. AND tx_nnctcp_domain_model_project.t3ver_state <= 0
    27. AND tx_nnctcp_domain_model_project.pid <> -1
    28. AND tx_nnctcp_domain_model_project.hidden = 0
    29. AND tx_nnctcp_domain_model_project.starttime <= 1360828500
    30.  
    31. AND
    32.  
    33. (
    34. tx_nnctcp_domain_model_project.endtime = 0
    35. OR
    36. tx_nnctcp_domain_model_project.endtime > 1360828500
    37. )
    38.  
    39. AND tx_nnctcp_domain_model_project.sys_language_uid IN (0,-1)
    40. AND tx_nnctcp_domain_model_project.pid IN (73, 77, 78-)
    41. AND tx_nnctcp_domain_model_institute.deleted = 0
    42. AND tx_nnctcp_domain_model_institute.t3ver_state <= 0
    43. AND tx_nnctcp_domain_model_institute.pid <> -1
    44. AND tx_nnctcp_domain_model_institute.hidden = 0
    45. AND tx_nnctcp_domain_model_institute.starttime <= 1360828500
    46.  
    47. AND
    48.  
    49. (
    50. tx_nnctcp_domain_model_institute.endtime = 0
    51. OR
    52. tx_nnctcp_domain_model_institute.endtime>1360828500
    53. )
    54.  
    55. AND tx_nnctcp_domain_model_institute.sys_language_uid IN (0,-1)
    56. AND tx_nnctcp_domain_model_institute.pid IN (73, 77, 78-)
    57. AND tx_nnctcp_domain_model_country.deleted = 0
    58. AND tx_nnctcp_domain_model_country.t3ver_state <= 0
    59. AND tx_nnctcp_domain_model_country.pid <> -1
    60. AND tx_nnctcp_domain_model_country.hidden = 0
    61. AND tx_nnctcp_domain_model_country.starttime <= 1360828500
    62.  
    63. AND
    64.  
    65. (
    66. tx_nnctcp_domain_model_country.endtime = 0
    67. OR
    68. tx_nnctcp_domain_model_country.endtime > 1360828500
    69. )
    70.  
    71. AND tx_nnctcp_domain_model_country.sys_language_uid IN (0,-1)
    72. AND tx_nnctcp_domain_model_country.pid IN (73, 77, 78-)
    73.  
    74. ORDER BY tx_nnctcp_domain_model_project.refid ASC

    1. public function findBySearch(array $sterm,$sorting = "title",$order = "ASC") {
    2. // Ggf. überschreibt der Benutzer Query
    3. if ( ($userQuery = $this->getUserQuery(__FUNCTION__)) != false ) return $this->executeUserQuery($userQuery);
    4.  
    5. // Query vorbereiten
    6. $query = $this->createQuery();
    7. $logicalAnd = array($query->in('pid',$this->getPidList(false,__FUNCTION__)));
    8.  
    9. // Suchkriterien bilden
    10. if ( $sterm['title'] != '' ) array_push($logicalAnd, $query->like('title','%'.$sterm['title'].'%'));
    11. if ( $sterm['refid'] > 0 ) array_push($logicalAnd, $query->like('refid','%'.(integer)$sterm['refid'].'%'));
    12. if ( $sterm['subject'] > 0 ) array_push($logicalAnd, $query->equals('subjects.uid',(integer)$sterm['subject']));
    13. if ( $sterm['collaboration'] > -1 ) array_push($logicalAnd, $query->equals('collaboration_type',(integer)$sterm['collaboration']));
    14. if ( $sterm['institute'] > 0 ) array_push($logicalAnd, $query->equals('institutes.uid',(integer)$sterm['institute']));
    15. if ( $sterm['status'] > -1 ) array_push($logicalAnd, $query->equals('status',(integer)$sterm['status']));
    16. if ( $sterm['country'] > 0 ) array_push($logicalAnd, $query->logicalOr(
    17. # DEBUG: Dies führt zu einem doppelten Join und damit SQL Fehler, Lösung???
    18. $query->equals('coordinatingInstitute.country.uid',(integer)$sterm['country']),
    19. $query->equals('institutes.country.uid',(integer)$sterm['country'])
    20. ));
    21.  
    22. // Sortierung festlegen
    23. $order = ( $order === 'ASC' ) ? Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING : Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING;
    24.  
    25. // Ausführen und Ergebnis
    26. return $query->matching($query->logicalAnd($logicalAnd))->execute();
    27. }

    TypoScript kann alles, auch kochen! ...Man muss nur wissen wie ;-)

    Take a look at my TYPO3 Extensions in the Repository:
    content_designer, k23_imagecrop, nn_address and more...

  • 1