Magento数据库多表联查之join
来源:互联网 发布:php 共享变量 编辑:程序博客网 时间:2024/05/16 15:35
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;
- Magento数据库多表联查之join
- Magento数据库多表联查之join
- mysql数据库之left join与join
- 关于magento collection的join
- 数据库性能优化之JOIN方法
- Oracle数据库 Left Join 使用之我见
- SQL Server数据库之left join 、right join 和 inner join 的区别
- [数据库]sql之left join、right join、inner join的区别
- 数据库join
- 数据库join
- magento 多表相同列名join
- magento--------------数据库操作
- 如何恢复 magento数据库
- Magento数据库表结构
- Magento数据库结构:EAV
- Magento迁移数据库
- Magento操作数据库
- magento直接操作数据库
- RT73 wifi无线网卡驱动移植过程
- 菜鸟养成记----大图轮换
- Struts2开发步骤
- SQL SERVER insert/delete/update 中的 ouput语句
- perl system和exec 调用
- Magento数据库多表联查之join
- 文件的压缩与解压
- 硅谷土豪新玩具:特斯拉P85D
- jQuery源码分析-08队列 Queue
- HttpContext.Current
- C语言之选择排序
- XYWi-Fi v2.0 简单的笔记本无线热点分享工具【Win】
- 修改Cocos2dx中的CCMessageBox的按钮文字
- Java学习路线图