I have been searching for a couple hours for a way to accomplish this task (which I know is fairly elementary), but I can't find any documentation...
I have three models - reviews, users, and books - and I'm designing the review controller and add action for that controller. I already have the user_id pulled from the session and used to populate the review to be "written by that user." However, what is the best way to add in the book that is being reviewed? Also, is there a way to populate the "create" page with book information from the book model?
I'm thinking of having the URL be /reviews/1/ format, where 1 is the book_id, but having create($id = null), but how do I translate that into a read command and integrate it into the data variable?
Any help would be greatly appreciated!
EDIT: This is how my controller looks now:
function create() {
if($this->Review->create($this->data) && $this->Review->validates()) {
$this->data['Review']['user_id'] = $this->Session->read('Auth.User.id');
$this->Review->save($this->data);
$this->redirect(array('action' => 'index'));
} else {
$errors = $this->Review->invalidFields();
}
}