Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.15 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.         /**
  4.          * Person
  5.          *
  6.          * Application model for `Person` records.
  7.          *
  8.          * Schema: id, father_id, mother_id, first_name, last_name
  9.          *
  10.          * @author Joe Beeson <jbeeson@gmail.com>
  11.          */
  12.         class Person extends AppModel {
  13.  
  14.                 /**
  15.                  * "Belongs to" associations.
  16.                  *
  17.                  * @var array
  18.                  * @access public
  19.                  */
  20.                 public $belongsTo = array(
  21.                         'PersonMother' => array(
  22.                                 'className' => 'Person',
  23.                                 'foreignKey' => 'mother_id'
  24.                         ),
  25.                         'PersonFather' => array(
  26.                                 'className' => 'Person',
  27.                                 'foreignKey' => 'father_id'
  28.                         )
  29.                 );
  30.  
  31.                 /**
  32.                  * "Has many" associations.
  33.                  *
  34.                  * @var array
  35.                  * @access public
  36.                  */
  37.                 public $hasMany = array(
  38.                         'PersonChildren' => array(
  39.                                 'className' => 'Person',
  40.  
  41.                                 /**
  42.                                  * Since we have [two] fields that could possibly associate us
  43.                                  * to our `PersonChild` records we have to override the query
  44.                                  * to make sure we're searching both.
  45.                                  */
  46.                                 'finderQuery' => 'SELECT `PersonChildren`.* FROM `people` AS `PersonChildren` WHERE `PersonChildren`.`father_id` IN ({$__cakeID__$}) OR `PersonChildren`.`mother_id` IN ({$__cakeID__$})',
  47.  
  48.                                 // Note we also need to say false to "foreignKey"
  49.                                 'foreignKey' => false
  50.                         )
  51.                 );
  52.  
  53.         }