[TYPO3-mvc] Left join query

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jun 28 10:11:24 CEST 2010


Hey Daniel,

>> 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.

yes, that's what I meant.


>> 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

Then try $query->contains('keywords',$keyword) instead of 
$query->equals('keywords',$keyword). If that still doesn't work there's 
maybe something wrong with your TCA settings.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list