SQLSTATE [42000]の原因は何ですか:構文エラーまたはアクセス違反:1064テーブルをグループ化しようとするとき。

magento.stackexchange https://magento.stackexchange.com/questions/11131

質問

コレクションの参加を作成し、main_tableでグループ化しようとするときに、例外が原因であるものを把握しようとしています。

これが私の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;
    }
}

私に悲しみを与えている線は次のとおりです。

$select->group('main_table.comment_id');

私が修正できないように見えるエラーをスローしているので

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`

誰かが使用する正しい構文を知っている場合は、親切にアドバイスしてください。または、私のコードに逃したエラーがある場合は、アドバイスしてください。

よろしくお願いします!

役に立ちましたか?

解決

問題は確かに4行目でした

$select->where('order.customer_id?', $customer->getId());

である必要があります

$select->where('order.customer_id=?', $customer->getId());
ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top