Cakephp habtm relation unable to correctly filter by tag -


i have habtm relation between users , tags. however, works such our list of tags maintained separately users. such there 12 tags , n users. new users added, tagged different tags , deleted, number of tags not change, records in taggings_users table increase accurately reflect everyone's tags. part works.

additionally, there interface allows users filter tagged users tags. interface designed such if user a has tags monday , tuesday show in search either. additionally, if user b has tags monday , wednesday , search preformed search users include tag monday , exclude tag wednesday user b should not show (exclusions trump inclusions).

cake able manage requiring included tags in search, , separately, cake able manage requiring tags excluded. trouble making cakephp "know" when user c has tags x , z , search preformed requested users including tag x , excluding tag z user c should not appear. presently user c appear in results.

i realize result of join operation has preformed on db. i.e. since user c has 2 tags, user has 2 records returned db. cake correctly ignores one, other has correct tag , allows user c enter result sets not intended user. there way make cake solve issue. can fix on server (removing user c in controller, feel i'm missing easy). query gets users consideration tags:

$conditions = array(     'and' => array(         'tagging.tag_name' => array(             (int) 0 => 'tech'         ),         'not' => array(             'tagging.tag_name' => array(                 (int) 0 => 'monday'             )         )     ) );  // using join options preform search $joins[] = array(     'table'         =>  'taggings_users',     'alias'         =>  'tagginguser',     'type'          =>  'inner',     'conditions'    =>  array(         'user.id = tagginguser.user_id'     ) );  $joins[] =  array(     'table'         =>  'taggings',     'alias'         =>  'tagging',     'type'          =>  'inner',     'conditions'    =>  array(         'tagginguser.tagging_id = tagging.id'     ) );  // powers operation $this->paginate = array( 'conditions' => $conditions, 'joins' => $joins, 'limit' => 50 );  // there users in here should not $users = $this->paginate('user');  // thank helps. 

without testing think work when add join:

$joins[] =  array(     'table'         =>  'taggings',     'alias'         =>  'tagging2',     'type'          =>  'inner',     'conditions'    =>  array(         'tagginguser.tagging_id = tagging2.id'     ) ); 

note changed "alias" "tagging2". , then

$conditions = array(     'and' => array(         'tagging.tag_name' => array(             (int) 0 => 'tech'         ),         'not' => array(             'tagging2.tag_name' => array(                 (int) 0 => 'monday'             )         )     ) ); 

additionaly dont think "(int) 0" syntax necessary. should enough write

$conditions = array(     'and' => array(         'tagging.tag_name' => 'tech',         'not' => array(             'tagging2.tag_name' => 'monday'         )     ) ); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -