问题
if you use the QueryInterface from Typo3 or Flow3 you can look up in the QueryInterface Extbase Dokumentation for all functions you can use. I already created some ANDs, ORs and LogicalNOTs in Flow3 and they work great.
My problem is the in() function. Let's say I have a "task" object and every task has one "status" object (over Many-To-One). Now I want to have all tasks having a status with the 'show' attribute on 'false'. That's what doesn't work:
$query->in('status',$this->statusRepository->findByShow(FALSE));
I guess it's because of the return value types of find(). You can get 'NULL', one object or many objects in an array. But why it doesn't work and how can I fix it?
Thanks for help.
回答1:
It should work like this (assuming the set of status objects is not empty):
$query = $this->createQuery();
$query->matching($query->in('status', $this->statusRepository->findByShow(FALSE)));
return $query->execute();
回答2:
When you call findByShow, it return an object of QueryResult, the second parameters in the "in" method should be an array of mixed elements.
Try to use the toArray() method of QueryResult to convert your object into an array of your status model.
$this->statusRepository->findByShow(FALSE)->toArray();
I hope it helped!
Olivier
回答3:
I'm not sure if they fixed this by now but I remember spending hours last year to find out I had to do this:
$statusIds = Array();
$status = $this->statusRepository->findByShow(FALSE);
foreach($status as $s) $statusIds[] = $status->getIdentifier();
$constraint = $query->in('status',$statusIds);
return $query->matching($constraint)->execute();
Your Status class must implement the following:
public getIdentifier(){ return $this->Persistence_Object_Identifier; }
来源:https://stackoverflow.com/questions/17864051/in-method-typo3-queryinterface