OK, that's ... six (?!) hours of my life I'll never get back. I've
been chipping away at this, adding all kinds of debug() lines in Model
& ClassRegistry, becoming convinced the latter had a bug whereby two
models couldn't use the same plugin behavior.

And then I looked--once again, but with a bit more attention--at the
output of ClassRegistry::keys(), saw that I had both Comments.Comment
*and* Comment. That's when the lightbulb clicked on. I went straight
to my User model and saw that I'd forgotten to remove the Comment
association! The behavior adds these in setup()..

What I still don't understand is why this worked fine for Gallery,
though. But I kind of don't care at this point.

On Thu, Oct 21, 2010 at 6:14 PM, cricket <[email protected]> wrote:
> 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