Jeff McClure Tue Jun 12 13:07:33 -0400 2012

Subject: Limit to Depth of Include ( nested queries )

Is there a limit to the supported depth of inlcudes for the find method - or am I calling this incorrectly?

This does not work:

// Php Version 5.3.10 : MySQL Ver 14.14 Distrib 5.5.9, for osx10.6
// Result -> Undefined offset: 0 Table.php line 257

$model = 'a';
$data = $model::find('all', array( 'include' => array( b' => array( c' => array( 'd' ) ) ) ) );

however, this does work:

$model = 'a';
$data = $model::find('all', array( 'include' => array( 'b' => array( 'c' ) ) ) );

Models:

// a
static $has_many = array(
array( 'b' ),
array( 'c', 'through' => 'b' ),
array( 'd', 'though' => 'c' )
);

// b
static $belongs_to = array(
array( 'a' ),
array( 'c' )
);

// c
static $has_many = array(
array( 'd' ),
array( 'e', 'through' => 'd' ),
array( 'b' ),
array( 'a', 'through' => 'b' )
);

// d
static $belongs_to = array(
array( 'c' ),
array( 'e' )
);

// Database Table Structure (enforced using innoDB foreign key constraints)
table a : int(11) id [ PK ]
table b : int(11) a_id, int(11) c_id [ combined as PK ]
table c : int(11) id [ PK ]
table d : int(11) c_id, int(11) e_id [ combined as PK ]
table e : int(11) id [PK]

Any ideas?


Brian Zeligson Mon Jul 23 10:01:55 -0400 2012

Just fixed this for myself by changing line 247 of Table.php in execute_eager_load from

if (is_array($name))
{
$nested_includes = count($name) > 1 ? $name : $name[0];//<-- this line
$name = $index;
}

to

if (is_array($name))
{
$nested_includes = count($name) > 0 ? $name : $name[0];
$name = $index;
}

(1-1/1)