I have 2 tables books and authors, one join table authors_books.
books and author tables have a primary key called id and other info
fields.
Join table has one pk called id and two fk called book_id and
author_id.
Book model is something like that:
<?php
class Book extends AppModel{
var $name = 'Book';
var $hasAndBelongsToMany = 'Author';
?>
and Author model is pretty similar:
<?php
class Author extends AppModel{
var $name = 'Author';
var $hasAndBelongsToMany = 'Book';
?>
I have function called add() in books_controller.php:
function add() {
if (!empty($this->data)) {
if ($this->Book->save($this->data)) {
$this->Session->setFlash('Your book has been
saved.');
$this->redirect(array('action' => 'index'));
}
else
{
$this->Session->setFlash("An error has occured,
check all form
fields.");
}
}
}
and I have a form in the view:
<?php
echo $form->create('Book');
// error instruction
echo $form->input('author', array('type' => 'text', 'label' =>
'Author name:' ));
echo $form->input('title', array('type' => 'text', 'label' => 'Book
title:' ));
echo $form->end('Save Album');
?>
When I send this form, only books table is filled with data (e.g.
Title is inserted correctly in books table). authors and authors_books
tables are not filled with any data.
Why? Where I wrong, i've followed all naming convention (I suppose).
Regards
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en