[TYPO3-mvc] Left join query

Daniel Dimitrov danielsd_bg at yahoo.fr
Tue Jun 29 11:21:57 CEST 2010


Hey Franz, hey Nikolas,
Thank you both very much for your replies!
I have to say that extbase is f..... scaring and amazing me at the same 
time. It looks so complicated, I have no idea what goes in the background 
and at the same time it looks so easy.

Now I've tried what Nikolas said:
"public function findByKeywords($keywords) {
$query = $this->createQuery();
return $query->matching($query->in('keywords.keyword', $keywords))
->execute();
}"

it didn't work... Then I tried what Franz said:
> public function findByKeywords(array $keywords, $limit=9999, $offset=0) {
>     $query = $this->createQuery();
>     return $query->matching(
>            $query->contains('keywords', $keywords)
>         )
>         ->setLimit((integer) $limit)
>         ->setOffset((integer) $offset)
>         ->execute();
> }
>
> If that doesn't work, try $query->equals('keywords', $keywords) or 
> $query->in('keywords.uid',$keywords);

it didn't work...

Then I started renaming Tx_BwShop_Domain_Model_Keywords to 
Tx_BwShop_Domain_Model_Keyword
and wrote the following query:
public function findByKeywords(array $keyword, $limit=9999, $offset=0) {
		$query = $this->createQuery();
		return $query->matching(
						($query->equals('keywords.uid', $keyword))
				)
				->setLimit((integer) $limit)
				->setOffset((integer) $offset)
				->execute();
	}
and then suddenly extbase made a left join query and there was a where 
statement with my_keywords_table.uid IN ().
Now I'm getting what I need and I'm really happy but at the same time I have 
no idea how I came to this result....

Cheers and thank you all!
Daniel


"Franz Koch" <typo3.RemoveForMessage at elements-net.de> wrote in message 
news:mailman.1.1277724184.24195.typo3-project-typo3v4mvc at lists.typo3.org...
> Hi,
>
> first, why is your model not named in singular if it reflects only one 
> keyword, not multiple? In my eyes Tx_BwShop_Domain_Model_Keyword would be 
> more appropriate.
>
>> What should I change in my findByKeywords function?
>>
>>      public function findByKeywords(Tx_BwShop_Domain_Model_Keywords
>> $keyword, $limit=9999, $offset=0) {
>>          $query = $this->createQuery();
>>          return $query->matching(
>>                          $query->contains('keywords', $keyword)
>>                  )
>>                  ->setLimit((integer) $limit)
>>                  ->setOffset((integer) $offset)
>>                  ->execute();
>>      }
>
>
> I don't think you have to change much, besides of passing the array with 
> keywords to that function instead of only one. So try this:
>
> public function findByKeywords(array $keywords, $limit=9999, $offset=0) {
>     $query = $this->createQuery();
>     return $query->matching(
>            $query->contains('keywords', $keywords)
>         )
>         ->setLimit((integer) $limit)
>         ->setOffset((integer) $offset)
>         ->execute();
> }
>
> If that doesn't work, try $query->equals('keywords', $keywords) or 
> $query->in('keywords.uid',$keywords);
>
> -- 
> kind regards,
> Franz Koch 



More information about the TYPO3-project-typo3v4mvc mailing list