在phpactiverecord三重水平协会 [英] Triple level associations in phpactiverecord

查看:167
本文介绍了在phpactiverecord三重水平协会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,如果我尝试渴望负荷超过深phpactiverecord两个对象,我得到一个错误。

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

什么是像这样的:

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

太多只是一个层面,试图找回?
我发现了一个错误未定义抵消:0 每当我尝试使用深协会3个级别。
感谢任何帮助或洞察力。:D

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.

编辑:

所以,我发现这是一个有些奇怪的图案。
如果我有阵列('playlist_songs'=>阵列('歌'=>阵列('专辑'))); ,热切负荷将打破我。但是,如果我添加其他关联数组,然后它工作正常。
阵列('playlist_songs'=>阵列(歌,歌,歌,歌=&G​​T;阵列('专辑')));

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.

推荐答案

只需要通过

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

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

这篇关于在phpactiverecord三重水平协会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆