Qual è la causa SQLSTATE [42000]: Errore di sintassi o violazione di accesso: 1064 quando si cerca di tabelle del gruppo?
-
16-10-2019 - |
Domanda
Ho cercato di capire che cosa sta causando l'eccezione quando si tenta di creare un join per le mie collezioni e raggrupparli con il main_table.
Ecco il codice dal mio Collection.php
<?php
class Companyname_CheckoutComments_Model_Resource_Comment_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{
protected function _construct() {
$this->_init('checkoutcomments/comment');
}
public function addCustomerFilter($customer){
$select = $this->getSelect();
if ($customer->getId()){
$select->where('order.customer_id?', $customer->getId());
} else {
//Force empty result set for not logged in customers
$select->where('1=0');
}
$select->join(array('order' => $this->getTable('sales/order')),
'order.entity_id = main_table.order_id',
array('status', 'created_at'));
$select->join(array('order_item' => $this->getTable('sales/order_item')),
'order_item.order_id = main_table.order_id
AND order_item.parent_item_id IS NULL ',
array());
/** Mage_Core_Model_Resource_Helper_Mysql4 */
Mage::getResourceHelper('core')->addGroupConcatColumn($select, 'product_names', 'order_item.name', ', ' );
$select->group('main_table.comment_id');
return $this;
}
}
La linea che mi sta dando il dolore è:
$select->group('main_table.comment_id');
Come si genera un errore che io non riesco a fix
QLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2') GROUP BY `main_table`.`comment_id`' at line 4
SELECT `main_table`.*, `order`.`status`, `order`.`created_at`, GROUP_CONCAT(order_item.name SEPARATOR ', ') AS `product_names` FROM `checkout_comments` AS `main_table` INNER JOIN `sales_flat_order` AS `order` ON order.entity_id = main_table.order_id INNER JOIN `sales_flat_order_item` AS `order_item` ON order_item.order_id = main_table.order_id AND order_item.parent_item_id IS NULL WHERE (order.customer_id'2') GROUP BY `main_table`.`comment_id`
Se qualcuno conosce la sintassi corretta da utilizzare si prega potrebbe consigliarvi gentilmente o se c'è qualche errore nel mio codice che ho perso.
Grazie in anticipo ragazzi!
Soluzione
Il problema è stato in effetti la linea 4
$select->where('order.customer_id?', $customer->getId());
deve essere
$select->where('order.customer_id=?', $customer->getId());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange