Count? Why didn't you say so?

You could easily extract the count from that result with:

count($result['Image'])); //http://us.php.net/manual/en/
function.count.php

Or:
There's probably a more elegant way to do this... In fact, in addition
to the techniques I'm illustrating, this page (http://book.cakephp.org/
view/1017/Retrieving-Your-Data) describes using sub-queries which may
be a way to do this.

However, this two step process get the job done.

$label = $this->Image->Gallery->find('first',array(
     'conditions'=> array(
          'Gallery.label'=>'seascape'),
     'fields'=>'Gallery.id')
);
$count = $this->Image->GalleryImage->find('count', array(
     'conditions'=> array(
          'GalleryImage.gallery_id'=>$label['Gallery']['id'])
));

Don

On May 19, 10:37 am, func0der <[email protected]> wrote:
> Thanks, but that is not what i am looking for.
>
> I want to do a count on all the images in the gallery.
> Your query just counts the galleries if i change "all" to "count".
> And also that query also get's all the other things attached to a
> gallery as well which i don't want to.
>
> I only want to count and/or receive the pictures within a gallery.
>
> On 19 Mai, 04:42, dreamingmind <[email protected]> wrote:
>
>
>
>
>
>
>
> > I have a habtm Image->GalleryImage->Gallery set up and can do what you
> > are looking for with this:
>
> > $this->Image->Gallery->find('all',
> > array('conditions'=>array('Gallery.name' => 'seascapes')));
>
> > Regards,
> > Don
>
> > On May 18, 3:15 pm, func0der <[email protected]> wrote:
>
> > > Hey guys,
>
> > > i'm just wondering how you can do a ordinary hasAndBelongsToMany query
> > > with cake without all these dynamic bindings and stuff.
>
> > > I'm having a gallery to galleryImages relationship but i can't search
> > > for images in a specific gallery over this relationship.
> > > This is maybe because i don't know how because i can't find a
> > > documentation or it's because CakePHP is not able to do it.
>
> > > Either one or the other way there is a question:
> > > How can i do it?
> > > or
> > > Why is CakePHP not able to do such queries?
>
> > > Greetings
> > > func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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