[TYPO3-core] RFC: Fix for bug #1649

Karsten Dambekalns karsten at typo3.org
Thu Dec 22 15:09:39 CET 2005


Hi Martin.

On Thursday 22 December 2005 11:46, Martin Kutschker wrote:
> $mmWhere.= $foreign_table ? $foreign_table.'.uid='.$mm_table.'.uid_foreign'
> : '';
>
> It's set BEFORE your conditional unsetting of $foreign_table.

Yes. Because we need that in the WHERE clause.

Unsetting it afterwards rmeoves a duplicate table name in the FROM part.

Image you have this call:
exec_SELECT_mm_query('uid,name','tx_something','tx_something_mm','tx_something')

Then you get this query with the old code:
 SELECT * FROM tx_something,tx_something_mm,tx_something WHERE
   tx_something.uid=tx_something_mm.uid_local AND
   tx_something.uid=tx_something_mm.uid_foreign
with two identical table names in the FROM part. This causes the error. With 
the change code the WHERE part stays the same, and afterwards the 
$foreign_table is unset, leading to a query like this:
 SELECT * FROM tx_something,tx_something_mm WHERE
   tx_something.uid=tx_something_mm.uid_local AND
   tx_something.uid=tx_something_mm.uid_foreign

> Anyway, if you have a self-referecingn relation you still have to have a
> "2nd" table. So that the statemen mentioned above makes sense. But you have
> to use SQL aliases.

The tx_something is there, without duplicate. No need for an alias. It could 
be used, but then you would run into the risk of using an alias that indeed 
already exists in the DB. Humpf. This way has no associated risk.

Karsten
-- 
Karsten Dambekalns
TYPO3 Association - Active Member
http://association.typo3.org/



More information about the TYPO3-team-core mailing list