Magento数据库多表联查之join
public function getOrderCollection() { $orders= Mage::getModel('sales/order')->getCollection(); $orders->getSelect() ->join( array('itemz'=> Mage::getSingleton('cor
Magento的数据读取是强大,但是封装的太深,太抽象。一天时间,就为了解决这个问题。一直没有在意方法的返回值。链式语句无法获取数据,却能正常打印SQL语句,并且该SQL语句在数据库中直接运行完美!
public
function
getOrderCollection() {
$orders
= Mage::getModel(
'sales/order'
)->getCollection();
$orders
->getSelect()
->join(
array
(
'itemz'
=> Mage::getSingleton(
'core/resource'
)->getTableName(
'sales/order_item'
)),
'main_table.entity_id = itemz.order_id'
,
array
(
'itemz.*'
)
);
return
$orders
;
}
在该方法中,getSelect()不能直接在getCollection()方法后使用链式方法调用。这样在模板文件中就能正常打印数据了
Magento的数据读取是强大,但是封装的太深,太抽象。一天时间,就为了解决这个问题。一直没有在意方法的返回值。链式语句无法获取数据,却能正常打印SQL语句,并且该SQL语句在数据库中直接运行完美!
public
function
getOrderCollection() {
$orders
= Mage::getModel(
'sales/order'
)->getCollection();
$orders
->getSelect()
->join(
array
(
'itemz'
=> Mage::getSingleton(
'core/resource'
)->getTableName(
'sales/order_item'
)),
'main_table.entity_id = itemz.order_id'
,
array
(
'itemz.*'
)
);
return
$orders
;
}
寻找XML:
$this->_initAction();
$this->_addContent(
$this->getLayout()->createBlock('cms/adminhtml_storelocator')
);
$this->renderLayout();
这个就是直接对应文件中的:cms--->adminhtml----->storelocator.php文件
复合查询:MAGENTO
select * from
salesrule_customer_relation p left join customer_entity q on q.entity_id = p.customer_id
$collection = Core::getModel ( 'salesrule/rule_customers' )->getCollection ()
->getSelect()
->joinLeft(array('p'=>'customer_entity'),'p.entity_id = main_table.customer_id','*');
echo $collection;die;
<?php echo Core::getModel('core/store')->load('oldnavy_cn_cn')->getCurrentUrl() ?> 跳转网站
$pid=83;
$collection_of_products = Core::getModel('checkout/salesordergift')->load($pid,'order_id');
print_r ($collection_of_products->getData());
die;
更多推荐
所有评论(0)