[TYPO3-dev] do I need reverse relation?
Peter Russ
peter.russ at 4many.net
Fri Oct 13 13:49:52 CEST 2006
Bartosz Aninowski schrieb:
> Hi list
> This is my scenario.
> I have table with products and mm relations to shops tables where user can
> buy these products.
> If BE user adds new product he select also shops where products is on
> stock..
> I want to show all shops where particular product is available.
> I've tried this code but I think this is wrong. This query duplicates items
> on page.
>
>
> //$this->piVars['prodUid'] is uid of clicked product
>
> if($this->piVars['prodUid']) $mm_cat =
> array('table'=>'tx_bapogromcy_products','mmtable'=>'tx_bapogromcy_products_shops_mm');
> $res =
> $this->pi_exec_query('tx_bapogromcy_shop',0,$where,$mm_cat,'','','');
> $count =
> $this->pi_exec_query('tx_bapogromcy_shop',1,$where,$mm_cat,'','','');
>
> I think I need select like this uid_foreign = tx_bapogromcy_shop.uid and
> tx_bapogromcy_products.uid = prodUid but I could be wrong :)
>
> Thanks in advance
Hi Bartosz,
1) tslib_pibase::exec_query gives you a lot of overhead. It might be
easier to go with t3lib_db::exec_SELECT_mm_query
2) To answer your question:
Your mm_table stores the realtion products<->shops so
tx_bapogromcy_products.uid=tx_bapogromcy_products_shops_mm.uid_local
and
tx_bapogromcy_shops.uid=tx_bapogromcy_products_shops_mm.uid_foreign
This releation will be handled by default with the tslib_pibase query.
BUT: You try to query tx_bapogromcy_shop based on above realtion. So
this will mix up uid_local and uid_foreign. Check
tslib_pibase::pi_list_query
...' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '...
At the moment I'm not aware of a switch to handle that "reverse"
3) I would try s.th. like
$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
'ts.*',
'tx_bapogromcy_shop as ts,
left join tx_bapogromcy_products_shops_mm as txm1 on
txm1.uid_foreign=ts.uid,
left join tx_bapogromcy_products as tp on tp.uid=txm1.uid_local and
tp.uid='.addslashes($this->piVars['prodUid']
);
Not tested - just an idea and hopes that might help.
Regs. Peter.
--
Fiat lux!
Docendo discimus.
_____________________________
4Many® Services
openBC: http://www.openbc.com/go/invuid/Peter_Russ
More information about the TYPO3-dev
mailing list