Reputation: 2670
With :
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Post', true));
$this->redirect(array('action' => 'index'));
}
$this->set('post', $this->Post->read(null, $id));
}
I can find related Users, but Users have Profile.
When I list related users, I want to have Profile Email instead of profile_id
Post $hasAndBelongsToMany Users $belongsTo Profile.
Tables:
Users
Posts_Users
Posts
Profiles.
ANSWER :
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Post', true));
$this->redirect(array('action' => 'index'));
}
$this->Post->recursive =2;
$this->set('post', $this->Post->read(null, $id));
}
Upvotes: 1
Views: 1816
Reputation: 7585
you should not be using recursive 2, containable is the thing you want. http://book.cakephp.org/view/1323/Containable
Upvotes: 1