It matches if the $operand equals the value of the property named
$propertyName. If $operand is NULL a strict check for NULL is done. For
strings the comparison can be done with or without case-sensitivity.
Note: case-sensitivity is only possible if the database supports it. E.g.
if you are using MySQL with a case-insensitive collation you will not be able
to test for case-sensitive equality (the other way around works, because we
compare lowercased values).
public equals ( string $propertyName, mixed $operand, boolean $caseSensitive = true ) : object | ||
$propertyName | string | The name of the property to compare against |
$operand | mixed | The value to compare with |
$caseSensitive | boolean | Whether the equality test should be done case-sensitive for strings |
return | object |
/** * @test */ public function comlexQueryWithJoinsCanBeExecutedAfterDeserialization() { $postEntityRepository = new Fixtures\PostRepository(); $postEntityRepository->removeAll(); $commentRepository = new Fixtures\CommentRepository(); $commentRepository->removeAll(); $testEntity1 = new Fixtures\Post(); $testEntity1->setTitle('Flow'); $postEntityRepository->add($testEntity1); $testEntity2 = new Fixtures\Post(); $testEntity2->setTitle('Flow with comment'); $comment = new Fixtures\Comment(); $comment->setContent('Flow'); $testEntity2->setComment($comment); $postEntityRepository->add($testEntity2); $commentRepository->add($comment); $this->persistenceManager->persistAll(); $query = new Query(Fixtures\Post::class); $query->matching($query->equals('comment.content', 'Flow')); $serializedQuery = serialize($query); $unserializedQuery = unserialize($serializedQuery); $this->assertEquals(1, $unserializedQuery->execute()->count()); $this->assertEquals([$testEntity2], $unserializedQuery->execute()->toArray()); }
/** * @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; }