On Thu, Mar 24, 2011 at 3:20 AM, thom <[email protected]> wrote: > Hello, I have a problem on joining tables. Exactly, it's custom query > pagination case. But, I am stucked at 'joining' table thing. I've > stucked since yesterday (what a shame).. > > Here is the case. I have a table relationship using belongsTo, but I > still wanna 'JOIN' it with 2 more tables. So, in controller, I join > it. > > #code# > var $paginate = array( > 'limit' => 10, > 'joins' => array( > array( > 'table' => 'poschecks', > 'alias' => 'Poscheck', > 'type' => 'LEFT', > 'conditions' => array( > 'Poscheck.id = > Visit.poscheck_id' > ) > ), > array( > 'table' => 'grouptariffs', > 'alias' => 'Grouptariff', > 'type' => 'LEFT', > 'conditions' => array( > 'Grouptariff.id = > Tariff.grouptarif_id' > ) > ) > ), > 'conditions' => "Visit.tanggal >= '2011-03-01' AND > Visit.tanggal <= > '2011-03-31'" > ); > > > What happen is, it gimme query error. After I look at the > displayed-query, It has wrong position. > > .............. > LEFT JOIN poschecks AS `Poscheck` ON (`Poscheck`.`id` = `Visit`.`poscheck_id`) > LEFT JOIN grouptariffs AS `Grouptariff` ON (`Grouptariff`.`id` = > `Tariff`.`grouptarif_id`) > > LEFT JOIN `tariffs` AS `Tariff` ON (`Expense`.`tarif_id` = `Tariff`.`id`) > LEFT JOIN `visits` AS `Visit` ON (`Expense`.`visit_id` = `Visit`.`id`) > LEFT JOIN `workers` AS `Worker` ON (`Expense`.`worker_id` = `Worker`.`id`) > > WHERE > `Visit`.`tanggal` >= '2011-03-01' AND `Visit`.`tanggal` <= '2011-03-31' > > The first two LEFT JOIN, is the join from the controller that I added. > But the problem is, those should be above/below the last line (LEFT > JOIN `workers` AS `Worker` ON (`Expense`.`worker_id` = `Worker`.`id`) > ). If I edited the query then replace it to the right position and run > it on the phpmyadmin, it works and give me results what I expected. > > The question is how I solve this case? I mean how to place the first 2 > lines below the 'JOIN' made by my model? > Thank you for any help..
Perhaps you need to unBind() the other associations and then add those joins to $paginate, as well. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
