[TYPO3-mvc] Left join query

Daniel Dimitrov danielsd_bg at yahoo.fr
Mon Jun 28 09:42:27 CEST 2010


Hi Franz,
Thank you for your reply.

"Franz Koch" <typo3.RemoveForMessage at elements-net.de> wrote in message 
news:mailman.1.1277476659.25070.typo3-project-typo3v4mvc at lists.typo3.org...
> 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:

Do you call bidirectional relation the thing that Felix explained in his 
mail from 27.05.2010 11:51?
mm_oposite_field: 
http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.1.0/view/4/2/
if yes, then yes I have set such relation. I can assign a product to a 
keyword and a keyword to a product.

>
> 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()
> }
> }

I've tried this already, but the sad thing is that I get an array with 0 
elements. And when introduce an error in the query (ordering by a field that 
doesn't exist) I see that extbase tries the following query:
SELECT tx_bwshop_domain_model_products.* FROM 
tx_bwshop_domain_model_products WHERE 
tx_bwshop_domain_model_products.keywords = '623' AND 
tx_bwshop_domain_model_products.deleted=0 AND 
tx_bwshop_domain_model_products.hidden=0 AND 
tx_bwshop_domain_model_products.pid IN (47448, 93) ORDER BY date DESC LIMIT 
0, 9999

tx_bwshop_domain_model_products.keywords  stores just a number of keywords 
the product has, not the actual keyword id - this query is never going to 
return an array with products since it doesn't make a join with the mm 
table.

>
> -- 
> kind regards,
> Franz Koch

Kind regards,
Daniel 



More information about the TYPO3-project-typo3v4mvc mailing list