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 |
public function equals($propertyName, $operand, $caseSensitive = true)
{
$aliasedPropertyName = $this->getPropertyNameWithAlias($propertyName);
if ($operand === null) {
return $this->queryBuilder->expr()->isNull($aliasedPropertyName);
}
if ($caseSensitive === true) {
return $this->queryBuilder->expr()->eq($aliasedPropertyName, $this->getParamNeedle($operand));
}
return $this->queryBuilder->expr()->eq($this->queryBuilder->expr()->lower($aliasedPropertyName), $this->getParamNeedle(UnicodeFunctions::strtolower($operand)));
}
/** * @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()); }