mneuhaus/TYPO3.Flow — pull request #19 by mneuhaus-bot (2014-03-20 09:13:48+00:00)
Title: [FEATURE] Make JOINs for property path idempotent (Revision 5)

The Flow query interface and -builder used to add
a dedicated JOIN for every property involved in a
constraint, even if for this property a JOIN already
has been created. So, constructions like

$query->logicalAnd(
$query->contains('categories.posts', $blogPost),
$query->equals('categories.approved', TRUE)
)

resulted in a DQL reading like

SELECT e FROM Acme\Post e
LEFT JOIN e.categories categories0
LEFT JOIN e.categories categories1
WHERE ?1 MEMBER OF categories0.posts
AND categories1.approved = ?2

Shortly said, multiple invocations of

\TYPO3\Flow\Persistence\Doctrine\Query::getPropertyNameWithAlias('categories.approved')

result into

categories0.approved
categories1.approved
categories2.approved

etc.

This, at the end, likely resulted into unpredicted
matches because it would match those Posts where
a category having approved = false is involved in
the post in question, as long as this category belongs
to an (arbitrary) Post having any category approved = true.

Introducing this patch, the already done JOINs are
bookmarked by their alias and not again defined if
the same property occurs. The final DQL would read like

SELECT e FROM Acme\Post e
LEFT JOIN e.categories ecategoriesjoin
WHERE ?1 MEMBER OF ecategoriesjoin.posts
AND ecategoriesjoin.approved = ?2

Releases: master
Change-Id: I4b25f44f34cf0bb88e683610e74206adaa735425
Revision-Id: f2883051b2de27fd61e34fa1fb4664f0ef949180