user4246509
user4246509

Reputation:

join 3 tables on cakephp

I'm trying to join 3 tables using cakephp but I don't understand why when I execute my query there is the result of the main tables without the attributes from the other 2 tables . this is my php code :

$flightSchedule = $this->FlightSchedules->find('all', array(
    'join' => array(
        array(
           'table' => 'WeeklySchedules',
           'alias' => 'ws',
           'type' => 'INNER',
           'conditions' => array(
           'FlightSchedules.code = ws.flight_plan_code'
        ),
        array(
           'table' => 'Structures',
           'alias' => 's',
           'type' => 'LEFT',
           'conditions' => array(
           'FlightSchedules.code = s.flight_plan_code',
       )),
    )),
    'conditions' => array(
        'FlightSchedules.plane_code' => 'xxx'
     ),
));

the result of this is always the FlightSchedules record without the join of the other tables . Any ideas how to fix this ?

Upvotes: 0

Views: 861

Answers (2)

user8301234
user8301234

Reputation:

use "fields" for display the data of an associated table .

  $flightSchedule = $this->FlightSchedules->find('all', array(
            'join' => array(
                array(
                   'table' => 'WeeklySchedules',
                   'alias' => 'ws',
                   'type' => 'INNER',
                   'conditions' => array(
                   'FlightSchedules.code = ws.flight_plan_code'
                ),
                array(
                   'table' => 'Structures',
                   'alias' => 's',
                   'type' => 'LEFT',
                   'conditions' => array(
                   'FlightSchedules.code = s.flight_plan_code',
               )),
            )),
            'conditions' => array(
                'FlightSchedules.plane_code' => 'xxx'
             ),
        'fields'=>'FlightSchedules.*,ws.*,s.*'

        ));

Upvotes: 1

502_Geek
502_Geek

Reputation: 2136

Add this in after condition array

'fields' => 'FlightSchedules.*, WeeklySchedules.*, Structures.*'

Upvotes: 0

Related Questions