[TYPO3-mvc] Left join query
Daniel Dimitrov
danielsd_bg at yahoo.fr
Fri May 28 10:37:54 CEST 2010
Hey Felix,
I was suspecting something like this. At the end extbase is all magic :)
Anyway I couldn't make it. I've set the mm_opposite_field.
Then I've fetched my keyword model and made
$keyword->getProducts(), but what I get is a big NULL.
Here is my keywords model, what could I have done wrong?
class Tx_BwShop_Domain_Model_Keywords extends
Tx_Extbase_DomainObject_AbstractEntity {
protected $keyword;
/**
*
* @var Tx_BwShop_Domain_Model_Products
*/
protected $products;
public function getKeyword(){
return $this->keyword;
}
public function getProducts() {
return $this->products;
}
}
Kind regards,
Daniel
"Felix Oertel" <typo3 at foertel.com> wrote in message
news:mailman.1.1274954152.16041.typo3-project-typo3v4mvc at lists.typo3.org...
> Hey
>
> On 2010-05-27 11:32:55 +0200, Daniel Dimitrov said:
>> Come on guys, I think that this really deserve at least a small
>> explanation or a nice tutorial :)
>
> ok, small answer: you don't need join queries ;)
>
>> "Daniel Dimitrov" <danielsd_bg at yahoo.fr> wrote in message
>> news:mailman.1.1274346762.31732.typo3-project-typo3v4mvc at lists.typo3.org...
> I
>>
>>> have a productobject, that can have multiples keywords.
>>> Product object is stored in - tx_bwshop_domain_model_products
>>> I have an mm relation table tx_bwshop_keywords_mm
>>> And the keywords table tx_bwshop_domain_model_keywords
>>>
>>> When I'm showing a list with all products, then extbase make some magic
>>> tricks and I can see all the keywords for a product :)
>>>
>>> The thing is that I have a search mask where I can search for a keyword
>>> and I have to show all products for this keyword and its children.
>
> there's a mm-relation between your products and your keywords. first you
> have to make sure that extbase can follow this relation in both directions
> (means products have a field "keywords" with MM set and keywords have a
> field "products" with MM and (!) MM_oposite_field (to "keywords") set [*])
>
> if you want to search for all products containing a keyowrd you just fetch
> the keyword-model via the keyword-repository (with
> matching(like($searchphrase)) or similar and then do
> $keyword->getProducts() as extbase mapps all products containing this
> keyword-model into that property itself ;-) Why do you want to join
> yourself? Extbase loves you and takes care for everything *g
>
> regards, foertel
>
> PS: if you really want to get the products yourself (which hardly makes
> sense, cause you have to get the keyword-model upfront anyway) you can do
> something like products=>matching(contains('keywords', $keywordModel)) ...
> extbase won't build a join for you but use a subselect in SQL's IN() - the
> result is the same (at least the resultSET is *g)
>
> [*] if anyone is confused by this I suggest to take a look at all fields
> starting with MM_ at
> http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.1.0/view/4/2/#id4224554
>
More information about the TYPO3-project-typo3v4mvc
mailing list