I'm using cakephp framework. I have two tables on my DB, courses and modules table. Those tables are related, courses has many modules. Basically I want to get data on courses and on modules but with specific fields. I want to get just the id and the title of the course and the id and the title of the module.
This code:
$courses_taken = $this->Course->find('all', array(
'conditions' => array('Course.id' => $course_id_list),
'fields' => array('Course.id', 'Course.title')
));
gives me:
array(
(int) 0 => array(
'Course' => array(
'id' => '1',
'title' => 'course 1'
),
'Module' => array(
(int) 0 => array(
'id' => '1',
'course_id' => '1',
'title' => 'module 1',
'image' => null,
'content' => 'Lorem ipsum',
'voice_over' => null,
'created' => '2014-09-03 14:02:25',
'modified' => '2014-09-03 14:02:28'
),
(int) 1 => array(
'id' => '2',
'course_id' => '1',
'title' => 'module 2',
'image' => null,
'content' => 'Sasdas',
'voice_over' => null,
'created' => null,
'modified' => null
)
)
),
(int) 1 => array(
'Course' => array(
'id' => '2',
'title' => 'course 2'
),
'Module' => array()
)
)
But I wanna select a specific field for module as well so I tried this code:
$courses_taken = $this->Course->find('all', array(
'conditions' => array('Course.id' => $course_id_list),
'fields' => array('Course.id', 'Course.title', 'Module.id', 'Module.title')
));
but gives me an error: Column not found: 1054 Unknown column 'Module.id' in 'field list'. Please help me guys thanks.