Skip to content

Instantly share code, notes, and snippets.

@hmic
Created August 10, 2017 13:59
Show Gist options
  • Save hmic/85669d2c45d0e0d06a1006f186e04637 to your computer and use it in GitHub Desktop.
Save hmic/85669d2c45d0e0d06a1006f186e04637 to your computer and use it in GitHub Desktop.
hasMany association on cake2 with *very* custom finder example
<?php
class AModel {
var $hasMany = array(
'Field' => array(
'className' => 'Field',
'foreignKey' => '',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
// {$__cakeID__$}
'finderQuery' => 'SELECT * FROM `fields` as `Field` WHERE `Field`.`id` IN (SELECT `field_id` FROM `category_fields` as `CategoryField` WHERE `category_id` = (SELECT `category_id` FROM `items` WHERE `items`.`id` = {$__cakeID__$})) ORDER BY `Field`.`order`',
'counterQuery' => 'SELECT COUNT(*) FROM `fields` as `Field` WHERE `Field`.`id` IN (SELECT `field_id` FROM `category_fields` as `CategoryField` WHERE `category_id` = (SELECT `category_id` FROM `items` WHERE `items`.`id` = {$__cakeID__$}))'
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment