[TYPO3-mvc] How to check in a Query if sub-objects exist?

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Thu Oct 13 03:21:40 CEST 2011


Hi there,

is there a way of checking just for the existance of sub-objects?

I.e. without writing a SQL query of my own?

Here is a sample to make clear what i mean:


public function findByDemand(... $demand) {
     $query = ...

     if (($property = $demand->getProp1()) !== NULL) {
         $constraints[] = $query->equals('prop1', $property);

     [etc. for diff. requested properties...]

     if ($demand->getHasPropXY() == true) {
         $constraints[] = $query->(???);
     }

     $query->matching($query->logicalAnd($constraints));
     $query->execute();
}

$demand::hasPropXY is set bei a checkbox of a multi search form.

The query should return all records which have (sub-)objects of propXY, 
where propXY  has a 1:n or m:n relation to the parent.

I tried this:
     if ($demand->getHasPropXY() == true) {
         $constraints[] = $query->logicalNot($query->equals('propXY', NULL);
     }
but the result makes no sense...

In SQL this would be just an inner join without using the fields of the 
right table...

Any help wpuld be much appreciated!
Cheers,
Till


More information about the TYPO3-project-typo3v4mvc mailing list