加入不在CakePHP 3中工作

时间:2016-08-04 10:57:45

标签: cakephp inner-join jointable cakephp-3.2

我在controller中使用此代码来获取连接结果,而不是包含CakePHP 3.2中的关联

$abc = $this->Products->SellerProducts->find('all', [
          'conditions' => [
            'Products.subcategory_id' => $id,
            'SellerProducts.stock >' => 0,
          ],
          'join' => [
            'products' => [
              'table' => 'Products',
              'type' => 'INNER',
              'conditions' => [
                'products.id = SellerProducts.product_id'
              ]
            ],
            'brands' => [
              'table' => 'Brands',
              'type' => 'INNER',
              'conditions' => 'brands.id = products.brand_id'
            ],
            'product_colors' => [
              'table' => 'ProductColors',
              'type' => 'INNER',
              'conditions' => 'product_colors.product_id = products.id'
            ],
            'colors' => [
              'table' => 'Colors',
              'type' => 'INNER',
              'conditions' => 'colors.id = product_colors.color_id'
            ]
          ]
        ]);

但在debug上,它只提供SellerProducts的数据,不包括(加入)其他表。

我希望使用contain方法得到连接结果而不是关联结果,因为contain给出了多级数组,很难从多级数组中获取关联数据。

  

编辑2:调试结果($ abc);

SELECT SellerProducts.id AS `SellerProducts__id`, SellerProducts.seller_id AS `SellerProducts__seller_id`, SellerProducts.product_id AS `SellerProducts__product_id`, SellerProducts.selling_price AS `SellerProducts__selling_price` FROM seller_products SellerProducts INNER JOIN Products products ON products.id = SellerProducts.product_id INNER JOIN Brands brands ON brands.id = products.brand_id INNER JOIN ProductColors product_colors ON product_colors.product_id = products.id INNER JOIN Colors colors ON colors.id = product_colors.color_id WHERE (Products.subcategory_id = :c0 AND SellerProducts.stock > :c1)

2 个答案:

答案 0 :(得分:0)

我想你可能会为所有领域写这样的文字:

$this->SellerProducts->find('all',['fields' => [], 'conditions' => []]

OR

$this->SellerProducts->find('all', [
      'conditions' => [
        'Products.subcategory_id' => $id,
        'SellerProducts.stock >' => 0,
      ]])->join(.....);

See Cakephp 3 join

答案 1 :(得分:0)

试试这个

            Intent intent = new Intent(context, ConversationActivity.class);
            intent.putExtra(ConversationUIService.TAKE_ORDER, true);//flag to disable list after back press  
            intent.putExtra(ConversationUIService.USER_ID, "userId");
            intent.putExtra(ConversationUIService.DISPLAY_NAME, "display name");
            startActivity(intent);