06.22 php saved
chatmasta
Tags add more
 
Note
In contrast to my previous paste, when I execute this much more complicated find() operation, ImagetypesLayout does not find its associated Image entry like I want. I know that it recognizes the association because I am not getting the error message "ImagetypesLayout is not associated with model Image."
  1. $this->Restaurant->Layout->Imagetype->ImagetypesLayout->bindModel(
  2.                 array('hasAndBelongsToMany' => array(
  3.                     'Image' => array(
  4.                         'className' => 'Image',
  5.                         'joinTable' => 'images_imagetypes_layouts',
  6.                         'foreignKey' => 'imagetypes_layout_id',
  7.                         'associationForeignKey' => 'image_id',
  8.                         'unique' => true,
  9.                         'conditions' => '',
  10.                         'fields' => '',
  11.                         'order' => '',
  12.                         'limit' => '',
  13.                         'offset' => '',
  14.                         'finderQuery' => '',
  15.                         'deleteQuery' => '',
  16.                         'insertQuery' => ''
  17.                     )
  18.                 )
  19.             ));
  20.         //debug($this->Restaurant->Layout->Imagetype->ImagetypesLayout->find());
  21.         $this->Restaurant->recursive = 5;
  22.         debug($this->Restaurant->find('first', array(
  23.                         'contain' => array(
  24.                             'Layout' => array(
  25.                                 'Imagetype' => array(
  26.                                     'ImagetypesLayout' => array(
  27.                                         'Image',
  28.                                     )
  29.                                 )
  30.                             )
  31.                         ),
  32.                         'conditions' => array(
  33.                             'Restaurant.name' => $this->r_name
  34.                         )
  35.                     )));
  36.  
  37. Produces:
  38.  
  39. (
  40.     [Restaurant] => Array
  41.         (
  42.             [id] => 4
  43.             [name] => macruno
  44.             [info] => Mmmm, Macruno fries!
  45.             [layout_id] => 1
  46.         )
  47.  
  48.     [Layout] => Array
  49.         (
  50.             [id] => 1
  51.             [title] => example
  52.             [Imagetype] => Array
  53.                 (
  54.                     [0] => Array
  55.                         (
  56.                             [id] => 1
  57.                             [title] => header
  58.                             [ImagetypesLayout] => Array
  59.                                 (
  60.                                     [id] => 1
  61.                                     [imagetype_id] => 1
  62.                                     [layout_id] => 1
  63.                                 )
  64.  
  65.                         )
  66.  
  67.                     [1] => Array
  68.                         (
  69.                             [id] => 2
  70.                             [title] => footer
  71.                             [ImagetypesLayout] => Array
  72.                                 (
  73.                                     [id] => 2
  74.                                     [imagetype_id] => 2
  75.                                     [layout_id] => 1
  76.                                 )
  77.  
  78.                         )
  79.  
  80.                 )
  81.  
  82.         )
  83.  
  84. )
  85.  
Parsed in 0.131 seconds, using GeSHi 1.0.7.14

Modify this Paste