Other cakephp way is as below.
You can also set association to Student model as below.
In Student Model add below code
var $belongsTo = array
(
'StudentExtra'=>array
(
'className' => 'Student',
'foreignKey' => 'parent_id'
)
);
In controller
$this->set('students', $this->paginate('Student'));
Now just do a pr($students); exit();
to test result in view or at the end of controller function.
You will see extra appended record array for StudentExtra which is all you need.
Now in view file display it as below.
<table>
<?php foreach ($students as $student){ ?>
<tr>
<td>
<?php $student['Student']['id'] ?>
</td>
</tr>
<tr>
<td>
<?php $student['Student']['name'] ?>
</td>
</tr>
<tr>
<td>
<?php $student['StudentExtra']['name'] ?>
</td>
</tr>
<?php } ?>
</table>
Answer Update response Code
$this->paginate = array
(
'joins'=>array
(
array
(
'table'=>'students',
'alias'=>'StudentExtra',
'type' =>'inner',
'conditions' =>array('StudentExtra.id IN (Student.parent_id)')
)
),
'limit'=> 10,
'order' => array('Student.name' => 'ASC')
);
$this->set('students', $this->paginate('Student'));
debug($this->paginate('Student'));
exit;