[TYPO3-mvc] Sort query results by a sub-model property

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Wed Feb 9 16:05:03 CET 2011


Marc Bastian Heinrichs wrote:
> Could you debug the resulting query in
> Tx_Extbase_Persistence_Storage_Typo3DbBackend::getObjectDataByQuery
> and post it? Thx

Hello Marc!

Thanks for your reply.

The resulting query is this one:

--------------------------------------------------
SELECT DISTINCT tx_hypeshowcase_domain_model_project.*
FROM   tx_hypeshowcase_domain_model_project
        LEFT JOIN tx_hypeshowcase_domain_model_product
          ON tx_hypeshowcase_domain_model_project.uid =
             tx_hypeshowcase_domain_model_product.project
WHERE  tx_hypeshowcase_domain_model_product.uid IN (SELECT uid_local
                                                     FROM
               tx_hypeshowcase_relation_product_service
                                                     WHERE  uid_foreign = 9)
        AND tx_hypeshowcase_domain_model_project.deleted = 0
        AND tx_hypeshowcase_domain_model_project.hidden = 0
        AND tx_hypeshowcase_domain_model_project.starttime<=1297263120
        AND ( tx_hypeshowcase_domain_model_project.endtime = 0
               OR tx_hypeshowcase_domain_model_project.endtime > 
1297263120 )
        AND tx_hypeshowcase_domain_model_project.pid IN ( 7, 9, 10, 11, 12 )
        AND tx_hypeshowcase_domain_model_product.deleted = 0
        AND tx_hypeshowcase_domain_model_product.hidden = 0
        AND tx_hypeshowcase_domain_model_product.starttime<=1297263120
        AND ( tx_hypeshowcase_domain_model_product.endtime = 0
               OR tx_hypeshowcase_domain_model_product.endtime > 
1297263120 )
        AND tx_hypeshowcase_domain_model_product.pid IN ( 7, 9, 10, 11, 12 )
ORDER  BY tx_hypeshowcase_domain_model_product.date DESC
--------------------------------------------------

Probably "ORDER  BY tx_hypeshowcase_domain_model_product.date DESC"
is wrong but I'm not sure, and I dunno how to set it right.

The repository method is this:

public function findByServices(array $services) {
	
	# create query
	$query = $this->createQuery();
	$query->setOrderings(array('products.date' => 
Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING));
	
	# chain constraints
	$constraints = array();
	foreach($services as $service) {
		array_push($constraints, $query->contains('products.services', $service));
	}
	
	# set conditions
	$query->matching($query->logicalOr($constraints));
	
	return $query->execute();
}

Thanks a lot for feedback!

Regards,
Thomas


More information about the TYPO3-project-typo3v4mvc mailing list