Don't ask me why, but now (maybe I changed that this morning and forgot
until now) there's a hasMany relationship from News to Comments.
The HABTM relationship is between News and Tags. I could have mixed
that up because of the early hour :)

Nevertheless, the problem is the same.

Some code snippets:

class News extends AppModel {
    var $hasMany = array(
        'Comments' => array(
            'className' => 'NewsComment',
            'order' => 'created DESC',
            'dependent' => true
        )
    );
}

class NewsComment extends AppModel {
    var $belongsTo = array(
        'News' => array(
            'className' => 'News'
        ),
        'Author' => array(
            'className' => 'User',
            'foreignKey' => 'author_id'
        )
    );
}


What I'm doing now as some kind of workaround, but shortened:

class News extends AppModel {
    function show($id) {
        // Fetch the item
        $news = $this->News->findById($id);

        $tempComments = array();

        /*
         * Fill in the comments with more detailed information
         */
        foreach ($news['Comments'] as $comment) {
            // Get full comment details
            $comment = $this->NewsComment->findById($comment['id']);

            // ...

            $tempComments[] = $comment;
        }

        // Overwrite the old comment array
        $news['Comments'] = $tempComments;

        $this->set('news_item', $news);
    }
}

You see, I'm fetching the entire comment in the foreach loop to get the
author's data. The array (using pr()) is finally rendered as desired
(see first post).
Now, each (numeric) comment entry in $news['Comments'] includes
[NewsComment], [Author] and [News] - the news item itself. It's waste
of bandwith, but I don't know what to do else to have [NewsComment] and
[Author].

I _could_ live without [Author] (the default case, described in 1st
post) because I'm able to fetch the user manually by ID. There are keys
titled 'author_name', 'author_email' and 'author_website' in the
comment's very own data and I fill in these fields manually for
registered users because they're only necessary if a guest is writing.
This way I can access $comment['author_website'] in the View, no matter
if the author was a guest or not.

Writing all this makes me think... :)
I changed a lot since this morning, so there's no necessity of having
the registered author's full profile anymore.
But I may run into the same problem with other models.
The point is that I don't understand _why_ there's no [Author] data by
default. It should be there - everything else is as well...


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to