[TYPO3-mvc] Persistence_rewrite merged!
Frans van der Veen
frans at netcreators.com
Mon Jul 13 03:20:11 CEST 2009
Hi,
Sebastian Kurfürst wrote:
> Hey everybody,
>
> thanks to the incredible work of Jochen we've finally merged back the
> persistence layer rewrite into extbase trunk!
Great work indeed!
When implementing my own Repository I ran into a few small bugs:
- $query->logicalOr, $query->logicalAnd do not work
(QueryObjectModelFactory calls makeInstance with non-existing classnames)
- Classes/Persistence/Query.php -> a few times $this is not returned,
preventing chaining.
- Classes/Persistence/Query.php -> like uses the wrong
$sourceSelectorName (now uses $this->getSource(), should be
$sourceSelectorName)
- Classes/Persistence/Storage/Typo3DbBackend.php: the getRows fails
chaining OR and NOT queries. Mainly because the $sql['where'] is
imploded with ' AND ' and the parseConstraint is adding loose '(' to the
where array.
See the fixes in the attached patch. Do you want me to create bugreports?
While playing around with the code I was wondering how to implement the
following in a repository:
- findByFirstLetter. This finds records by the first letter of the name
of the record.
For creating this functionality I had to create my own derived query
class (Tx_MyExtension_Persistence_Query), and a derived query factory
(Tx_MyExtension_Persistence_QueryFactory). The query class contains a
new method:
public function firstLetterEquals($propertyName, $operand,
$caseSensitive = TRUE) {
$propertyName = 'SUBSTRING('.$propertyName.',1,1)';
$comparison = $this->QOMFactory->comparison(
$this->QOMFactory->propertyValue($propertyName),
Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
$this->QOMFactory->bindVariable($propertyName)
);
}
Is this the best way to do this?
Let's say I want to find records on the name and I have two strings I
want to compare it with: testa and testb
$result = $query->matching(
$query->logicalOr(
$query->like('name', '%testa%'),
$query->like('name', '%testb%')
)
)
This will generated the following sql:
... AND ( (tx_myextension_domain_model_table.name LIKE '%testb%') OR
(tx_myextension_domain_model_table.name LIKE '%testb%') )
Because of the operands are stored in query in this associative array in
Tx_Extbase_Persistence_Query:
$this->operands[$propertyName] = $operand;
Appears to me not the intended behaviour?
And finally:
What would be the best way to create multiple OR / ANDs in a query:
select * from table where column1 like '%test%' or column2 like '%test%'
or column3 like '%test%'?
Doing it like this works:
$query->matching(
$query->logicalOr(
$query->like('column1', '%test%'),
$query->logicalOr(
$query->like('column2', '%test%'),$query->like('column3', '%test%')
)
)
The downside it adds extra '()' to the query, which could lead to
undesired results. Is this the way you intended it to work?
Thanks and keep up the good work!
Cheers,
Frans
More information about the TYPO3-project-typo3v4mvc
mailing list