has and belongs to many - Joins not used for complex HABTM search CakePhp 2 -


i have contents, can have tags belonging different taggroups. have quite complex search condition follows: content matches if tagged @ least 1 tag search long belongs same tag group.

example: taggroup 1 colours, taggroup2 shapes. if content tagged "blue", "turquoise" , "rectangular" found, when search "blue" , "rectangular" example show logic behind quite complex.

content -> contentstag <- tag -> taggroup

i want develop search paging of results had working, between refactoring , framework updates broken.

at point loose information joins , sql crashing because missing tables.

array(     'limit' => (int) 10,     'order' => array(         'content.objnbr' => 'asc'     ),     'joins' => array(         (int) 0 => array(             'table' => 'sang_contents_tags',             'alias' => 'ct1', //join first taggroup             'type' => 'inner',             'conditions' => array(                 (int) 0 => 'ct1.content_id = content.id'             )         ),         (int) 1 => array(             'table' => 'sang_contents_tags',             'alias' => 'ct2', //join second taggroup             'type' => 'inner',             'conditions' => array(                 (int) 0 => 'ct2.content_id = content.id'             )         )     ),     'conditions' => array(         'and' => array(             (int) 0 => array(                 'or' => array(                     (int) 0 => array(                         'ct1.tag_id' => '189' // chosen tag 1 first taggroup                     )                 )             ),             (int) 1 => array(                 'or' => array(                     (int) 0 => array(                         'ct2.tag_id' => '7' // chosen tag 2 second taggroup                     )                 )             )         )     ),     'contain' => array(         (int) 0 => 'description',         'contentstag' => array(             'tag' => array(                 (int) 0 => 'taggroup'             )         )     ) ) 

results in following sql:

select `content`.`id`, `content`.`objnbr`, `content`.`name`, `content`.`imagecounter`, `content`.`videolength`, `content`.`money_maker`, `content`.`comment`  `my_db`.`contents` `content`      ((`ct1`.`tag_id` = '189') , (`ct2`.`tag_id` = '7'))  order `content`.`id` desc  limit 20  

so tags ct1 , ct2 not joined , sql crashing.

could contain blocking joins? if unset contain still same result / error.

any ideas?

edit: clarify, want achieve: result should sql statement this:

select `content`.`id`, `content`.`objnbr`, `content`.`name`, `content`.`imagecounter`, `content`.`videolength`, `content`.`money_maker`, `content`.`comment`      `my_db`.`contents` `content`         inner join     contents_tags ct1 on ct1.content_id = content.id         inner join     contents_tags ct2 on ct2.content_id = content.id     ((`ct1`.`tag_id` = '189')         , (`ct2`.`tag_id` = '7')) order `content`.`id` desc limit 10 

it looks trouble caused pagination. if "simple" find contents based on tags:

$result = $this->content->find('all', $this->paginate['content']); 

generated query find:

select      `content`.`id`,     `content`.`objnbr`,     `content`.`name`,     `content`.`imagecounter`,     `content`.`videolength`,     `content`.`money_maker`,     `content`.`comment`     `my_db`.`contents` `content`         inner join     `my_db`.`contents_tags` `ct0` on (`ct0`.`content_id` = `content`.`id`)         inner join     `my_db`.`contents_tags` `ct2` on (`ct2`.`content_id` = `content`.`id`)     ((`ct0`.`tag_id` = '56')         , (`ct2`.`tag_id` = '7')) order `content`.`objnbr` asc 

i did research in bowels of pagination class , conclusion is, not able work current paginator, because cannot pass on special joins need complex query.

a custom find type not help, because query dynamic that.

should prove me wrong happy coder.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -