Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP - HABTM find() don't make the JOIN to other tables
    primarykey
    data
    text
    <p>My title will look like naive but I have to say I read/searched/tested everything possible, but my find() method don't implement the JOIN to related tables in the SQL query. I used it several times in other projects without problems but here...</p> <p>Here my 2 models (nothing special but the manual definition of the related model) :</p> <pre><code>class Pflanzen extends AppModel { public $useTable = 'pflanzen'; public $hasAndBelongsToMany = array( 'Herbar' =&gt; array( 'order'=&gt;'Herbar.order ASC', 'joinTable' =&gt; 'herbar_pflanzen', 'foreignKey' =&gt; 'pflanzen_id', 'associationForeignKey' =&gt; 'herbar_id') ); } class Herbar extends AppModel { public $useTable = 'herbar'; public $hasAndBelongsToMany = array( 'Pflanzen' =&gt; array('joinTable' =&gt; 'herbar_pflanzen', 'foreignKey' =&gt; 'herbar_id', 'associationForeignKey' =&gt; 'pflanzen_id') ) } </code></pre> <p>Here my query in the "Herbar" controller (can't be more normal...) :</p> <pre><code>$pflanzen = $this-&gt;Herbar-&gt;Pflanzen-&gt;find('all',array( 'fields'=&gt;array('Herbar.name','Pflanzen.linkplatter'), 'conditions' =&gt; array('Pflanzen.linkplatter' =&gt; true), 'order' =&gt; 'Herbar.name', 'limit' =&gt; 10, 'recursive'=&gt;2) ); $this-&gt;set('pflanzen',$pflanzen); </code></pre> <p>and the resulting error in the view :</p> <pre><code>Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Herbar.name' in 'field list' SQL Query: SELECT `Herbar`.`name`, `Pflanzen`.`linkplatter`, `Pflanzen`.`id` FROM `burgerbib`.`platter_pflanzen` AS `Pflanzen` WHERE `Pflanzen`.`linkplatter` = '1' ORDER BY `Herbar`.`name` ASC LIMIT 10 </code></pre> <p>You can see that their is no JOIN in the SQL. Why ?? What do I wrong ? I would really appreciate your help as I'm searching for hours and do no more see any solutions and didn't find nothing using google. Thanks in advance !!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload