Okay, I think this should work, but it doesn't. I've read through the
documentation and it all appears that I am doing the correct thing,
but it just isn't working for me. I'm really hoping that someone can
point out the "obvious" error that I'm completely missing here. :)

I'm trying to pull back a list of all my blogs along with all of the
associated comments for each blog. This is what I currently have:

table definitions: (I left out the data, but it is in there, trust
me...)
-------------------------------------------

CREATE TABLE `blogs` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(50) default NULL,
  `text` text,
  `post_date` datetime default NULL,
  `active` int(1) default NULL,
  `sort` int(11) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;

--
-- Table structure for table `comments`
--

CREATE TABLE `comments` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(75) NOT NULL default '',
  `text` text NOT NULL,
  `date` date NOT NULL default '0000-00-00',
  `author` varchar(100) NOT NULL default '',
  `blog_id` int(11) NOT NULL default '0',
  CONSTRAINT fk_comments_blog foreign key (blog_id) references
blogs(id),
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-------------------------------------------

comment.php
-------------------------------------------

class Comment extends AppModel {

        var $name = 'Comment';

        //The Associations below have been created with all possible keys,
those that are not needed can be removed
        var $belongsTo = array(
                        'Blog' =>
                                array('className' => 'Blog')

        );

}

-------------------------------------------

blog.php
-------------------------------------------

class Blog extends AppModel {

        var $name = 'Blog';
        var $hasMany = array('Comment' =>
                                 array('className'=>'Comment')
        );

        var $validate = array(
                'title' => VALID_NOT_EMPTY,
                'text' => VALID_NOT_EMPTY,
                'sort' => VALID_NUMBER,
        );
}

-------------------------------------------

>From blogs_controller.php
-------------------------------------------

        function cp_index() {
                $this->Blog->recursive = 0;

                $this->set('blogs', $this->Blog->findAll());
                $this->set('page_header', "Shoe Sole - List Blogs");
                $this->layout = 'list';
        }

-------------------------------------------

Now I would expect the $this->Blog->findAll() call to pull back an
array of blogs that has an array of comments within each respective
blog. However, this isn't the case. Instead it only pulls back blogs.

And don't worry, I do actually have comments that are related to these
blogs, In fact, the $belongTo portion of the comments section works
perfectly and associates one blog to each comment exactly as I would
expect.

So any help/guideance would be GREATLY appreciated.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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