Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

php - CakePHP HABTM association rules -


if want create category , able link products tags can so:

  • create category , product tables.
  • create tags table tags like: ruby, earrings, white-gold
  • create category_tags , product_tags table map them
  • set category , product hasandbelongstomany tags
  • set tags hasandbelongstomany products , hasandbelongstomany categories

now have 2 products 1 tags: ruby , earrings , tags: ruby , bracelet

say want create ruby earrings category.

i add ruby , earrings tags category. under normal habtm model associations both products returned because though 1 has earrings tag both have ruby tag.

how can make match products have of same tags category (products can have more tags must have tags corresponding category has) in order returned?

also, taking further, how add -tags category products must not have these tags returned?

the script below solved issue generating query so:

php

$data = $this->designer->find(     'first',      array(         'conditions' => array(             'designer.slug' => $name,              'designer.available' => 1         )     ) );  $inc_tag_ids = array(); $exc_tag_ids = array(); foreach($data["tag"] $tag) {     if( $tag['designerstag']['include'] )     {         $inc_tag_ids[] = $tag['id'];     }     else     {         $exc_tag_ids[] = $tag['id'];     } }  $ins = ' ';  if( count($inc_tag_ids) ) {     $inc_tag_id_str = '"' . implode('","',$inc_tag_ids) . '"';     $ins .= 'and tags.id in ('.$inc_tag_id_str.')'; }     if( count($exc_tag_ids) ) {     $exc_tag_id_str = '"' . implode('","',$exc_tag_ids) . '"';     $ins .= 'and products.id not in (         select products.id          products, products_tags, tags         products.id = products_tags.product_id          , tags.id = products_tags.tag_id          , tags.id in ('.$exc_tag_id_str.')     )'; }     $prod_qry = '     select *, count(distinct tags.name) uniques      products, products_tags, tags      products.id = products_tags.product_id      , tags.id = products_tags.tag_id      '.$ins.'     group products.id     having uniques = '.count($inc_tag_ids).'  ';  echo $prod_qry;  $data["matching_products"] = $this->designer->tag->query($prod_qry); 

sql

select * , count( distinct tags.name ) uniques products, products_tags, tags products.id = products_tags.product_id , tags.id = products_tags.tag_id , tags.id in ( "8" ) , products.id not  in (  select products.id products, products_tags, tags products.id = products_tags.product_id , tags.id = products_tags.tag_id , tags.id in ( "7" ) ) group products.id having uniques =1 

however feel not way cakephp inteded treated, think maybe should handled in model not in controller. not sure how that.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -