2012-04-02 55 views
0

現在,如果我嘗試在phpactiverecord中加載兩個以上的對象,我得到一個錯誤。phpactiverecord中的三級關聯

是下面這樣的:

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

只是一個太大的水平,試圖找回? 每當我嘗試使用3級深度的關聯時,都會收到錯誤Undefined offset: 0。 感謝您的幫助或見解:D。

編輯:

所以我發現了一個有點奇怪的模式。 如果我有array('playlist_songs'=>array('song'=>array('album')));,渴望的負載將爲我打破。但是,如果我將另一個關聯添加到數組中,它會正常工作。 array('playlist_songs'=>array('song','song','song','song'=>array('album')));

我在該數組中使用了'歌曲'多次,只是爲了使修復非常明顯。

回答

1

在execute_eager_load改變線路247 Table.php從

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

這是挽救生命的一半!我會在今天或明天的某個時間進行一些測試。 – Anther 2012-07-23 19:13:20

+0

這應該是說頭髮*。回想起來,那個評論看起來很不合適...... – Anther 2012-07-28 07:14:36

+0

很高興看到你進入回購庫了,謝謝你的關注! – 2013-02-28 17:48:51

0

這應該工作。一個例子,我剛剛測試了這個自己的代碼:

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

我能想到的唯一的事情是,你沒有任何結果的事情之一,或者你的條件包含以前別的東西使用數組?

+0

對於示例精確匹配的問題就解決了這個爲我自己,在包括陣列將需要查看像這樣:'array('include'=> array('Group'=> array('SomeGroupFeature'=> array('third_thing'))))';) – Anther 2012-04-09 15:42:08

+0

我要做更多的測試,看看是否這確實與空洞的結果有關,因爲我發現它確實按預期工作的情況下...... – Anther 2012-04-09 15:50:25