2011-06-30 36 views
1

我想通过加入'customer_entity_varchar'和'salesrule_coupon_usage'来显示基于'customer_id'的匹配数据。我如何在magento中执行连接?我必须运行原始sql查询来执行连接吗?在Magento中执行连接

回答

1

这不是正确的方式,但可能有里程为你在这种情况下:

$yourquery="SELECT * FROM customer_entity_varchar AS cev INNER JOIN salesrule_coupon_usage AS scu ON cev.customer_id=scu.customer_id WHERE blah blah"; 

$macguffin=Mage::getSingleton('core/resource')->getConnection('core_write'); 

$macguffin->query($yourquery); 

$yourqueryresult=$macguffin->fetch(PDO::FETCH_ASSOC); 

对于有道,看看在艾伦风暴指南“过滤数据库收藏”:

http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections/magento-for-dev-part-1-introduction-to-magento