2013-07-25 33 views
0

如果使用Typo3或Flow3中的QueryInterface,則可以在QueryInterface Extbase Dokumentation中查找可以使用的所有函數。我已經在Flow3中創建了一些AND,OR和LogicalNOT,並且它們工作得很好。- Typo3 - queryInterface

我的問題是in()函數。假設我有一個「任務」對象,每個任務都有一個「狀態」對象(通過「多對一」)。現在我想讓'show'屬性的所有任務都處於'false'狀態。這是不行的:

$query->in('status',$this->statusRepository->findByShow(FALSE)); 

我想這是因爲find()的返回值類型。您可以在數組中獲得'NULL',一個對象或多個對象。但爲什麼它不起作用,我該如何解決它?

感謝您的幫助。

回答

0

它應該像這樣(假設設置狀態的對象不爲空):

$query = $this->createQuery(); 
$query->matching($query->in('status', $this->statusRepository->findByShow(FALSE))); 
return $query->execute(); 
+0

這就是我已經擁有的。 ...如果我會在find上做一個count(),並且如果它是0什麼也不做,如果它是1和equals()以及in()中的多於1個狀態實體,你會說什麼? – Pete

+0

您現在使用的代碼會得到哪個錯誤? – Michael

+0

他無法構建查詢字符串... toString()中的錯誤 – Pete

0

當你調用findByShow,它在「入法」的返回QueryResult中的對象,第二個參數應是一組混合元素。

嘗試使用QueryResult的toArray()方法將您的對象轉換爲狀態模型的數組。

$this->statusRepository->findByShow(FALSE)->toArray(); 

我希望它有幫助!
奧利維爾

0

我不知道,如果他們修復了這個現在,但我記得花費數小時去年發現我不得不這樣做:

$statusIds = Array(); 
$status = $this->statusRepository->findByShow(FALSE); 
foreach($status as $s) $statusIds[] = $status->getIdentifier(); 
$constraint = $query->in('status',$statusIds); 
return $query->matching($constraint)->execute(); 

你的狀態類必須實現以下幾點:

public getIdentifier(){ return $this->Persistence_Object_Identifier; }