Monday, May 3, 2010

Simple assoication not working

I try to follow the example from a book called "CakePHP Application
Development"

I have created the following table under MySQL
books(id, isbn, title, description, author_id)
authors(id, name, email, website)

And created 4 .php files:

C:\xampp\htdocs\relationship\app\models\authors.php

<?php
class Author extends AppModel
{
var $name = 'Author';
var $hasMany = 'Book';
}
?>

C:\xampp\htdocs\relationship\app\models\books.php

<?php
class Book extends AppModel
{
var $name = 'Book';
var $belongsTo = 'Author';
}
?>

C:\xampp\htdocs\relationship\app\controllers\authors_controller.php

<?php
class AuthorsController extends AppController {
var $name = 'Authors';
var $scaffold;
}
?>

C:\xampp\htdocs\relationship\app\controllers\books_controller

<?php
class BooksController extends AppController {
var $name = 'Books';
var $scaffold;
}
?>

When I try to view the books (http://localhost/relationship/books),
author column only shows author_id but not the author name. Also,
under edit screen, the combo box for pick up author name is empty. I
also tried to remove $hasMany and $belongsTo and the result is the
same. It seems that the $hasManay and $belongsTo has no effect at
all.

Is there anything I missed?

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: