2013-07-25 31 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; }