Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Find method with JOIN in CakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 683
    Comment on it

    Hello, if you are working on cakephp and you need the joins with find method here is an example. Here $my_joins is and array having multiple join cases in other different arrays inside it.

    $my_joins=array(             
                'joins' =>
                          array(
                            array(
                                'table' => 'purchases',
                                'alias' => 'Purchase',
                                'type' => 'left',
                                'conditions'=> array('Deal.id = Purchase.deal_id')
                            )                      
             )  
        );
        $find_coupons = $this->Coupon->find('all',  $my_joins);
                                'foreignKey' => false,
                                'conditions'=> array('Purchase.id = Coupon.purchase_id')
                            ),
                            array(
                                'table' => 'deals',
                                'alias' => 'Deal',
                                'type' => 'left',
                                'foreignKey' => false,
                                'conditions'=> array('Deal.id = Purchase.deal_id')
                            )                      
             )  
        );
        $find_coupons = $this->Coupon->find('all',  $my_joins);
    

    This can added more inside $my_joins as equal to number of tables you want to compare.

    And in the last you can find method using 'all' over array $my_joins and you'll get the results

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: