• magento flat和eav表连接的不同


    对于flat表,也就是普通的表,例如订单之类的sales_flat_order,这类型的连接,Collection连接

     1     $table = Mage::getSingleton('core/resource')->getTableName('catalog_product_store');  
     2     $storetable = Mage::getSingleton('core/resource')->getTableName('core_store');  
     3                 $collection ->getSelect()->joinLeft(  
     4                             array('pstable' => $table),//表名称  
     5                             'e.entity_id=pstable.product_id',//表连接条件  
     6                             array('pstable.store_id as storeid')//选择出的字段  
     7                 );  
     8                 $collection ->getSelect()->joinLeft(  
     9                             array('storetable' => $storetable),//表名称  
    10                             'pstable.store_id=storetable.store_id',//表连接条件  
    11                             array('storetable.name as storename')//选择出的字段  
    12                 );  

    上述连接其实也适用于EAV模型的表,只是在grid过滤的情况下会出错。上述语句中

     1 storetable.name as storename  

    其实是防止grid表中重复的索引,比如某一个表的索引列叫  'index' => 'name'。而这个时候选出的字段就需要起个另外的别名,通过尝试以后发现 上述 代码 是可以执行成功的,可以得到想要的结果。

    对于eav模型的表连接,下述左连接来示例

     1     $collection ->joinField('storeid',  
     2                         'catalog_product_store',  
     3                         'store_id',  
     4                         'product_id=entity_id',  
     5                         null,  
     6                         'left');  
     7                $collection ->joinField('storename',  
     8                         'core_store',  
     9                         'name',  
    10                         'store_id=storeid',  
    11                         null,  
    12                         'left');  

    上述的连接其实是进行了两次连接,是有特点的,第一次连接的storeid用来作为第二次关联的条件。这种eav专属的连接,grid是不会过滤出错的。

  • 相关阅读:
    Java多线程(二) synchronized 针对对象进行锁定
    微信公众号 openId获取
    Java多线程(一) Thread和 Runnable
    设计模式
    vue城市选择组件
    分享几个简单的技巧让你的 vue.js 代码更优雅
    手把手教你vue配置请求本地json数据
    详解vue全局组件与局部组件使用方法
    细说vue axios登录请求拦截器
    在Vue项目中加载krpano全景图
  • 原文地址:https://www.cnblogs.com/zhengyanbin2016/p/5737326.html
Copyright © 2020-2023  润新知