Reputation: 171
Hey guys I am new to CakePHP and I am having a problem while joining two tables.
$options['joins'] = array(
array('table' => 'options',
'alias' => 'Options',
'type' => 'LEFT',
'fields' => array('Question.question', 'Options.option'),
'conditions' => array(
'Options.question_id = Question.id'))
);
$this->set('qq',$this->Question->find('all',$options));
I am getting only the fields of question table and not the fields of options table. How do I get the fields of options table also?
Upvotes: 1
Views: 281
Reputation: 27382
try to bind table.
$this->ModelName->bindModel(array
(
'belongsTo' => array
(
'ModelToJoin' => array
(
'foreignKey' => false,
'conditions' => array
(
'ModelToJoin.model_name_id = ModelName.id'
)
)
)
));
According to your situation.
<?php
$this->Question->bindModel(array
(
'hasMany' => array
(
'Options' => array
(
'foreignKey' => false,
'type' => 'LEFT',
'conditions' => array
(
'Options.question_id = Question.id'
)
)
)
));
$this->Question->find('all',array
(
'fields' => array('Question.question', 'Options.option')
));
Upvotes: 0