zoukankan      html  css  js  c++  java
  • 一次标准的关联查询

            $this->MerchantProduct->recursive = -1;
            $data = $this->MerchantProduct->find('first',
                    array(
                'fields' => array(
                    'MerchantProduct.*', 'Merchant.*'
                ),
                'joins' => array(
                    array(
                        'table' => 'merchants',
                        'alias' => 'Merchant',
                        'type' => 'inner',
                        'conditions' => array(
                            'Merchant.id = MerchantProduct.merchant_id',
                        )
                    ),
                ),
                'order' => 'MerchantProduct.id desc',
                'conditions' => array(
                'MerchantProduct.id' => $merchant_product_id,
                'MerchantProduct.active>=0',
            ))
            );
            $this->set(compact('data'));
            $this->loadModel('MerchantProductPicture');
            $this->MerchantProductPicture->cache = false;
            $carousel = $this->MerchantProductPicture->find('all', array(
                'limit' => 5,
                'fields' => array(
                    'MerchantProduct.*','MerchantProductPicture.*',
                ),
                'joins' => array(
                    array(
                        'table' => 'merchant_products',
                        'alias' => 'MerchantProduct',
                        'type' => 'inner',
                        'conditions' => array(
                            'MerchantProduct.id = MerchantProductPicture.product_id'
                        )
                    ),
                    array(
                        'table' => 'merchants',
                        'alias' => 'Merchant',
                        'type' => 'inner',
                        'conditions' => array(
                            'Merchant.id = MerchantProduct.merchant_id'
                        )
                    )
                ),
                'group' => 'MerchantProductPicture.product_id',
                'conditions' => array(
                    'MerchantProduct.active > 0',
                    'Merchant.user_id' => $user_id,
                    'MerchantProductPicture.use'=>'slider',
                )
            ));
            $this->set(compact('carousel'));

    下面这个是三张表关联

  • 相关阅读:
    flash
    三星核S5PV210AH-A0 SAMSUNG
    FATFS(A)
    DDR2是什么意思
    Java中的三大框架分别有什么用
    SD卡
    自动挡汽车档位介绍
    FSMC(STM32)
    陶瓷天线
    'telnet'不是内部或外部命令,怎么办?
  • 原文地址:https://www.cnblogs.com/linksgo2011/p/3013912.html
Copyright © 2011-2022 走看看