Hi all! Today was trying to learn associations but i couldn't succeed.
I'm getting some issue in getting associated array. I've two tables :
authors
        - id
        - name
        - email
        - website

books
        - id
        - isbn
        - title
        - description
        - author_id

controllers/authors_controller.php

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

                function index() {
                        $this->Author->recursive = 1;
                        $authors = $this->Author->find('all');
                        $this->set('authors', $authors);
                }
        }

controllers/books_controllers.php

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

                function index() {
                        $this->Book->recursive = 1;
                        $books = $this->Book->find('all');
                        $this->set('books', $books);
                }
        }

models/authors.php

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

models/books.php

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

books
id      isbn    title           description             author_id
1       12345   book1           asdfasdfasdf                    1
2       book2   asdfasfasdf ag as sadfas dfsdaf         1
3       345345  dfgvsdf         gsdgsdf sdfg sdfg dfg   2

authors

id      name                            email                                   
        website
1       Sams Publication        [email protected]       
http://www.samspublications.com
2       Test Author             [email protected]          
http://www.author1.com




When i try to run print '<pre>'; print_r($authors), i get following
array :

Array
(
    [0] => Array
        (
            [Author] => Array
                (
                    [id] => 1
                    [name] => Sams Publication
                    [email] => [email protected]
                    [website] => http://www.samspublications.com
                )

        )

    [1] => Array
        (
            [Author] => Array
                (
                    [id] => 2
                    [name] => Test Author
                    [email] => [email protected]
                    [website] => http://www.author1.com
                )

        )

)

So, my problem is that there's no Book array in above array. Please
help... Thanks in advance.

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

Reply via email to