gazareth
gazareth

Reputation: 1154

CakePHP join issue

This is driving me crazy. This is not throwing any errors but it is also not performing the joins. I'm hoping that this is one where I've spent too long looking at it and the answer is obvious to someone else...

        $lines = $this->RevenueLine->find('all', array(
                'conditions' => array(
                    'RevenueLine.is_triggered' => 1,
                    'RevenueLine.date_triggered >=' => $sqldate1,
                    'RevenueLine.date_triggered <=' => $sqldate2,
                ),
                'joins' => array(
                    array(
                        'table' => 'projects',
                        'alias' => 'Project',
                        'type' => 'INNER',
                        'conditions' => array(
                            'RevenueLine.project_id = Project.id'
                        )
                    ),
                    array(
                        'table' => 'clients',
                        'alias' => 'Client',
                        'type' => 'INNER',
                        'conditions' => array(
                            'Project.client_id = Client.id'
                        )
                    ),
                    array(
                        'table' => 'classifications',
                        'alias' => 'Classification',
                        'type' => 'INNER',
                        'conditions' => array(
                            'Project.classification_id = Classification.id'
                        )
                    )                       
                ),
                'order' => array(
                    'Client.client_number ASC', 
                    'Project.pn_counter ASC'
                )
            )
        );

Upvotes: 1

Views: 64

Answers (1)

Barry Chapman
Barry Chapman

Reputation: 6780

You need to select the fields from the joined tables:

'fields' => array(
     'JoinTable1.*',
     'JoinTable2.*',
     'JoinTable3.*',
     'JoinTable4.*'
)

as a parameter of your find.

Upvotes: 2

Related Questions