CakePHP加入问题

时间:2013-08-01 14:39:14

标签: cakephp

这让我发疯了。这不会引发任何错误,但它也没有执行连接。我希望这是一个我花了太长时间看待它的人,答案对其他人来说是显而易见的......

        $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'
                )
            )
        );

1 个答案:

答案 0 :(得分:2)

您需要从已连接的表格中选择字段:

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

作为你的发现的参数。