Magento / Zend Framework : Custom Join Statement : ERROR : Can't prepare expression when tableName is instance of Zend_Db_Expr
Magento / Zend Framework : Custom Join Statement : ERROR : Can't prepare expression when tableName is instance of Zend_Db_Expr
在 Magento v1 中,我尝试按如下方式添加自定义内部联接:
INNER JOIN (SELECT entity_id, LEFT(sku, 11) AS lwin11 FROM catalog_product_flat_1) AS test_lwin11 ON test_lwin11.entity_id = e.entity_id
我尝试使用
新 Zend_Db_Expr
$select->joinInner(['test_lwin11' => new Zend_Db_Expr('(SELECT entity_id, LEFT(sku, 11) AS lwin11 FROM catalog_product_flat_1)')], 'test_lwin11.entity_id = e.entity_id');
但这会抛出以下错误:
当 tableName 是 Zend_Db_Expr
的实例时无法准备表达式
有什么想法吗?
你可以试试:
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$tlw11 = $connection ->select()->from('catalog_product_flat_1', ['entity_id', 'lwin11' => 'LEFT(sku, 11)']);
然后
->join(['test_lwin11' => $tlw11], 'test_lwin11.entity_id = e.entity_id')
在 Magento v1 中,我尝试按如下方式添加自定义内部联接:
INNER JOIN (SELECT entity_id, LEFT(sku, 11) AS lwin11 FROM catalog_product_flat_1) AS test_lwin11 ON test_lwin11.entity_id = e.entity_id
我尝试使用 新 Zend_Db_Expr
$select->joinInner(['test_lwin11' => new Zend_Db_Expr('(SELECT entity_id, LEFT(sku, 11) AS lwin11 FROM catalog_product_flat_1)')], 'test_lwin11.entity_id = e.entity_id');
但这会抛出以下错误:
当 tableName 是 Zend_Db_Expr
的实例时无法准备表达式有什么想法吗?
你可以试试:
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$tlw11 = $connection ->select()->from('catalog_product_flat_1', ['entity_id', 'lwin11' => 'LEFT(sku, 11)']);
然后
->join(['test_lwin11' => $tlw11], 'test_lwin11.entity_id = e.entity_id')