make sure that in the database you have column comments.picture_id
which makes the relationship Picture has_many Comment.

You don't have to use belongs_to as that's just the inverse of
has_many. You can really make do with only one.

If you want, you can add another column, pictures.is_commented
(tinyint null default 0) and set it to 1 when picture receives the
first comment. Then, you can do $this->Picture-
>findAllByIsCommented(1); which will return you all pictures that have
been commented.

Otherwise, you'll have to do a LEFT JOIN on Picture and Comment and
see that Comment isn't empty, or perhaps use Containable behavior.
http://book.cakephp.org/view/1323/Containable

_V


On May 16, 9:06 am, spww <[email protected]> wrote:
> Hello there,
>
> I've got four models: User, Gallery, Picture, Comment
>
> Picture got the following relations set in its model.php:
>
> var $belongsTo = array('Gallery', 'User');
> var $hasMany = array('Comment' => array('dependent' => true));
>
> I've got a pagination based output of Picture which worked fine until
> I wanted to add a filter which should only display Pictures which have
> been commented.
>
> $this->paginate = array(
> 'conditions' => array('Picture.gallery_id' => $id),
> fields' => array('Picture.id', 'Picture.title', 'Picture.file',
> 'User.prename'),
> order' => 'Picture.position ASC',
> limit' => PAGINATION_PICTURE_LIMIT
> );
>
> On trying to add something like 'Comment.picture_id' => $id to the
> conditions cake reports that "Comment" does not exist.
> I found out that the belongsTo and hasMany associations are fetched
> with two separate queries from the db, so of course I cannot work with
> the model Comment in the conditions of the pagination.
>
> Is there anything I can do about it?
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 
> athttp://groups.google.com/group/cake-php?hl=en

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