0

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.

Pete
  • 564
  • 4
  • 29

3 Answers3

0

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();
Michael
  • 2,309
  • 1
  • 23
  • 34
  • that is what I allready have. ... what would you say if I will do a count() on the find and if it is 0 doing nothing, if it is 1 an equals() and more than 1 status entity the in() ? – Pete Jul 25 '13 at 22:03
  • he can't build the query string ... Error in toString() – Pete Jul 26 '13 at 09:54
  • Can you copy&paste the full error message? If you always only provide a little of your code or the error, it's not really helpful for finding a solution. – Michael Jul 26 '13 at 12:27
  • `Fatal error: Method Doctrine\ORM\Query\Expr\Func::__toString() must not throw an exception in C:\xampp\htdocs\Packages\Framework\Doctrine.ORM\Classes\Query\Expr\Func.php on line 0` – Pete Aug 01 '13 at 07:59
  • Have you googled that? I found your exact error message (`Fatal error: Method Doctrine\ORM\Query\Expr\Func::__toString() must not throw an exception`) in the [irc log](http://riesvantwisk.com/cms/home/irc-logs/typo3-flow-irc-log/2013/February/6.html) and somewhere below there is a `it works now, I had to...`. Have you tried that? – Michael Aug 01 '13 at 08:16
  • I foung that but that is just avoiding the problem. I don't get the useability of in(). Is that realy the in-clause of SQL? What does the second parameter await? – Pete Aug 01 '13 at 11:04
0

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

DaikonBoy
  • 158
  • 6
0

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; }
Ineluki
  • 118
  • 1
  • 7