I'm working on a Comment plugin that I want to use for several models.
One, Gallery, works perfectly. But another, Post, not so much.

Both models have $actsAs = array('Comments.Commentable');

In the behavior's afterFind() I have this line:

$data = $Model->Comment->threaded($Model->alias,
$result[$Model->alias][$Model->primaryKey]);

This is causing an error in Post because Cake is passing 'threaded' as
the SQL query, meaning that it couldn't find the method. In the stack
trace:

AppModel::threaded() - [internal], line ??
CommentableBehavior::afterFind() -
APP/plugins/comments/models/behaviors/commentable.php, line 61

If I put die(debug($Model)); just before that line, I can see that
Post does have the association ok:

    [hasMany] => Array
        (
            [Comment] => Array
                (
                    [className] => Comment
                    [foreignKey] => foreign_key
                    [unique] => 1
                    [conditions] => Array
                        (
                            [Comment.model] => Post
                        )

                    [fields] =>
                    [dependent] => 1
                    [order] =>
                    [limit] =>
                    [offset] =>
                    [exclusive] =>
                    [finderQuery] =>
                    [counterQuery] =>
                )

        )

In fact, if it didn't, PHP would crap out on
$Model->Comment->whatever() anyway. So, why would threaded() be called
on AppModel, instead of Comment, for Post, but not for Gallery? Again,
the entire plugin works just fine with Gallery.

It just occurred to me to put die(debug($Model->Comment)); instead.
For Gallery, I see "Comment Object" but Post shows "AppModel Object".
Even stranger, it shows, "[useTable] => comments" along with all the
correct column names for Comment. It's as if I've got some weird
hybrid thing going on here. What gives?!

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