Cakephp query doesn't render correct data

Posted by user2915012 on Stack Overflow See other posts from Stack Overflow or by user2915012
Published on 2013-10-24T09:27:27Z Indexed on 2013/10/24 9:54 UTC
Read the original article Hit count: 189

Filed under:
|
|

I'm totally new in cakephp and fetching problem at the time of query to render data

I tried this to find out categories/warehouses table info but failed..

    $cart_products = $this->Order->OrdersProduct->find('all', array(
                'fields' => array('*'),
                'contain' => array('Category'),
                'joins' => array(
                    array(
                        'table' => 'products',
                        'alias' => 'Product',
                        'type' => 'LEFT',
                        'conditions' => array('Product.id = OrdersProduct.product_id')
                    ),
                    array(
                        'table' => 'orders',
                        'alias' => 'Order',
                        'type' => 'LEFT',
                        'conditions' => array('Order.id = OrdersProduct.order_id')
                    )
                ),
                'conditions' => array(
                    'Order.store_id' => $store_id,
                    'Order.order_status' => 'in_cart'
                )
            ));

I need the result something like this...
Array
(
    [0] => Array
        (
            [OrdersProduct] => Array
                (
                    [id] => 1
                    [order_id] => 1
                    [product_id] => 16
                    [qty] => 10
                    [created] => 2013-10-24 08:04:33
                    [modified] => 2013-10-24 08:04:33
                )

            [Product] => Array
                (
                    [id] => 16
                    [part] => 56-987xyz
                    [title] => iPhone 5 battery
                    [description] => iPhone 5c description
                    [wholesale_price] => 4
                    [retail_price] => 8
                    [purchase_cost] => 2
                    [sort_order] => 
                    [Category] => array(
                           [id] => 1,
                           [name] => Iphone 5
                    )
                    [Warehouse] => array(
                           [id] => 1,
                           [name] => Warehouse1
                    )
                    [weight] => 
                    [created] => 2013-10-22 12:14:57
                    [modified] => 2013-10-22 12:14:57
                )
      )
)

How can I find this? Can anybody help me? thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql