문제

Right now if I try to eager load more than two objects deep in phpactiverecord, I get an error.

Is something such as this:

$conditions['include'] = array( 'playlists' => array('playlist_songs' =>array('song')));
User::find('first', $conditions);

Just one level too much to try to retrieve? I'm getting an error Undefined offset: 0 whenever I try to use an association 3 levels deep. Thanks for any help or insight :D.

Edit:

So I've found a pattern that's a little odd. If I have array('playlist_songs'=>array('song'=>array('album')));, the eager load will break for me. But if I add another association to the array, it then works correctly. array('playlist_songs'=>array('song','song','song','song'=>array('album')));

I used 'song' multiple times in that array just to make the fix very apparent.

도움이 되었습니까?

해결책

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;
}

다른 팁

This should work. An example I've just tested this my own code:

$model = MyItem::find('first',array('include' => array('Group' => array('SomeGroupFeature'))));

The only thing I can think of is that you don't have any results in one of the things, or your conditions contains something else from a previous use of the array?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top