Re: find all with at least one associated model

2010-11-03 Thread Max D
Thanks,

I'm now using the counter cache.
I tried the INNER join version as well and I got good looking result
arrays, but it seems using GROUP BY in pagination messes pagination
up.
$this->paginate = array(
'Blog' => array(
'joins' => array(
array(
'table' => 'posts',
'alias' => 'Post',
'type' => 'INNER',
'conditions' => array(
'Blog.id = Post.blog_id',
),
)
),
'group' => 'Blog.id',
)
);

$this->Paginator->counter always returned 1.

Anyway, having the counter_cache is nice anyway. So my problem is
solved.

On Nov 2, 9:12 am, ohcibi  wrote:
>  The easiest way would be to Use countercache and then just add
> post_count > 0 to conditions... if you cant zdf countercache for some
> reason you could also inner join the posts Table, which would leave
> all blogs that have no assocciated post...
> On 1 Nov., 18:29, Max D  wrote:
>
> > Hi,
>
> > i use cake 1.3 and I have a "Blog hasMany Post" association and now I
> > want to find all the Blogs, which have at least one Post. I use the
> > Containable Behavior.
>
> > I understand, that I could do a Blog->find('all', array('contain' =>
> > array('Post'))) and simply filter the results for the Blogs, where the
> > Post array is empty.
> > But this doesn't work if I want to use pagination.
>
> > I tried to paginate over the Post model:
> > $this->paginate = array('Post' => array(
> >         'contain' => array('Blog'),
> >         'order' => 'Blog.created DESC',
> >         'group' => 'Post.blog_id',
> >         'limit' => 5,
> > ));
> > $blog = $this->paginate('Post');
>
> > The Blog array looks good. I just get the Blogs with one Post each
> > (which I don't actually need). But all the PaginatorHelper functions
> > return wrong results.
> > $this->Paginator->counter(array('model' => 'Post'));
> > always returns 1, although there are 3 results in the $blogs array.
>
> > Any ideas how I can achieve this?
> > Thanks in advance
> > Max

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: find all with at least one associated model

2010-11-02 Thread ohcibi
 The easiest way would be to Use countercache and then just add
post_count > 0 to conditions... if you cant zdf countercache for some
reason you could also inner join the posts Table, which would leave
all blogs that have no assocciated post...
On 1 Nov., 18:29, Max D  wrote:
> Hi,
>
> i use cake 1.3 and I have a "Blog hasMany Post" association and now I
> want to find all the Blogs, which have at least one Post. I use the
> Containable Behavior.
>
> I understand, that I could do a Blog->find('all', array('contain' =>
> array('Post'))) and simply filter the results for the Blogs, where the
> Post array is empty.
> But this doesn't work if I want to use pagination.
>
> I tried to paginate over the Post model:
> $this->paginate = array('Post' => array(
>         'contain' => array('Blog'),
>         'order' => 'Blog.created DESC',
>         'group' => 'Post.blog_id',
>         'limit' => 5,
> ));
> $blog = $this->paginate('Post');
>
> The Blog array looks good. I just get the Blogs with one Post each
> (which I don't actually need). But all the PaginatorHelper functions
> return wrong results.
> $this->Paginator->counter(array('model' => 'Post'));
> always returns 1, although there are 3 results in the $blogs array.
>
> Any ideas how I can achieve this?
> Thanks in advance
> Max

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


find all with at least one associated model

2010-11-01 Thread Max D
Hi,

i use cake 1.3 and I have a "Blog hasMany Post" association and now I
want to find all the Blogs, which have at least one Post. I use the
Containable Behavior.

I understand, that I could do a Blog->find('all', array('contain' =>
array('Post'))) and simply filter the results for the Blogs, where the
Post array is empty.
But this doesn't work if I want to use pagination.

I tried to paginate over the Post model:
$this->paginate = array('Post' => array(
'contain' => array('Blog'),
'order' => 'Blog.created DESC',
'group' => 'Post.blog_id',
'limit' => 5,
));
$blog = $this->paginate('Post');

The Blog array looks good. I just get the Blogs with one Post each
(which I don't actually need). But all the PaginatorHelper functions
return wrong results.
$this->Paginator->counter(array('model' => 'Post'));
always returns 1, although there are 3 results in the $blogs array.

Any ideas how I can achieve this?
Thanks in advance
Max

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en