symql
symql copied to clipboard
Multiple where conditions giving SQL error
Version: 0.6.2 (Symphony 2.2.5)
I have the following in an event:
$products_query = new SymQLQuery();
$products_query
->select('name, brand, instances')
->from('products')
->perPage(999);
foreach ($_SESSION['sym-cart'] as $key => $item) {
$products_query->where('instances', $key);
}
$products = SymQL::run($products_query);
The instances
field is a SBL+ field.
When there is more than one product in the cart, meaning ->where
is called more than once, and the event is triggered:
Symphony Fatal Database Error
Not unique table/alias: 't137'
An error occurred while attempting to execute the following query
SELECT SQL_CACHE e
.id, e
.section_id, e.author_id
, UNIX_TIMESTAMP(e.creation_date
) AS creation_date
FROM sym_entries
AS e
LEFT JOIN sym_entries_data_137
AS t137
ON (e
.id
= t137
.entry_id) LEFT JOIN sym_entries_data_137
AS t137
ON (e
.id
= t137
.entry_id) WHERE 1 AND e
.section_id
= '1' AND t137
.relation_id IN ('1723') AND t137
.relation_id IN ('3096') ORDER BY e
.id
DESC LIMIT 0, 999
The t137
alias is created more than once.
When ->where
is called multiple times using system:id
, this error doesn't occur.