/** * @param ClassMetadata $targetEntity * @param string $targetEntityPropertyName * @return Query */ protected function getSubselectQuery(ClassMetadata $targetEntity, $targetEntityPropertyName) { $subselectQuery = new Query($targetEntity->getAssociationTargetClass($targetEntityPropertyName)); $propertyName = str_replace($targetEntityPropertyName . '.', '', $this->path); switch ($this->operator) { case '==': $subselectConstraint = $subselectQuery->equals($propertyName, $this->operand); break; case '!=': $subselectConstraint = $subselectQuery->logicalNot($subselectQuery->equals($propertyName, $this->operand)); break; case '<': $subselectConstraint = $subselectQuery->lessThan($propertyName, $this->operand); break; case '>': $subselectConstraint = $subselectQuery->greaterThan($propertyName, $this->operand); break; case '<=': $subselectConstraint = $subselectQuery->lessThanOrEqual($propertyName, $this->operand); break; case '>=': $subselectConstraint = $subselectQuery->greaterThanOrEqual($propertyName, $this->operand); break; case 'like': $subselectConstraint = $subselectQuery->like($propertyName, $this->operand); break; case 'in': $subselectConstraint = $subselectQuery->in($propertyName, $this->operand); break; } $subselectQuery->matching($subselectConstraint); return $subselectQuery; }
/** * @test */ public function comlexQueryWithJoinsCanBeExecutedAfterDeserialization() { $postEntityRepository = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\PostRepository(); $postEntityRepository->removeAll(); $commentRepository = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\CommentRepository(); $commentRepository->removeAll(); $testEntity1 = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\Post(); $testEntity1->setTitle('Flow'); $postEntityRepository->add($testEntity1); $testEntity2 = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\Post(); $testEntity2->setTitle('Flow with comment'); $comment = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\Comment(); $comment->setContent('Flow'); $testEntity2->setComment($comment); $postEntityRepository->add($testEntity2); $commentRepository->add($comment); $this->persistenceManager->persistAll(); $query = new Query(\TYPO3\Flow\Tests\Functional\Persistence\Fixtures\Post::class); $query->matching($query->equals('comment.content', 'Flow')); $serializedQuery = serialize($query); $unserializedQuery = unserialize($serializedQuery); $this->assertEquals(1, $unserializedQuery->execute()->count()); $this->assertEquals(array($testEntity2), $unserializedQuery->execute()->toArray()); }
/** * @param Query $query * @param AssetCollection $assetCollection * @return void */ protected function addAssetCollectionToQueryConstraints(Query $query, AssetCollection $assetCollection = null) { if ($assetCollection === null) { return; } $constraints = $query->getConstraint(); $query->matching($query->logicalAnd($constraints, $query->contains('assetCollections', $assetCollection))); }