[TYPO3-mvc] Left join query

Franz Koch typo3.RemoveForMessage at elements-net.de
Fri Jun 25 16:33:01 CEST 2010


Hey Daniel,

>> Yes, you will get ALL objects, as all objects are related to that
>> keyword. If that doesn't work for you with having 10.000 products on a
>> keyword, you have to find a different way, maybe by using a
>> productsService returning only a limited subset of the assigned
>> products using a special method of your productRepository (like
>> $this->productRepository->findByKeyword($keyword, $offset, $limit)).
> Ok, that is actually the problem
>
> if I write my own function findByKeyword - i have to make somehow a join
> there.
> keyword -> mm_table -> products.
>
> with this
> $keyword = $this->keywordsRepository->findByUid($this->filter['kw']);
> $products = $keyword->getProducts();
> extbase resolved the products on its own. Now if I wish to use
> repository function I have to write
> that join query and this is something that I don't understand how to do.

I suppose you have a bidirectional relation, so your keywords know about 
your products and your products have keywords assigned. Now you want to 
fetch only products with a certain keyword, right? If so, try this:

class Tx_YourExt_Domain_Repository_ProductRepository extends ... {

	public function findByKeyword (Tx_YourExt_Domain_Model_Keyword 
$keyword, $limit=9999, $offset=0, array $orderings) {
		$query = $this->createQuery();
		return $query->matching(
			  $query->equals('keywords',$keyword)
			)
			->setLimit((integer) $limit)
			->setOffset((integer) $offset)
			->setOrderings($orderings)
			->execute()
	}
}

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list