Saturday, June 27, 2009

Re: Containable grabbing too much data

Thanks for posting that. I also have an afterFind callback in the
model that is giving me too much data, so that must be the problem.
I'm kinda glad it's not because I wasn't understanding 'contain'
behaviour. Unfortunately the afterFind contains some logic that I
can't do without, so I'll have to stick with a custom query solution I
think.

On Jun 28, 10:02 am, Miles J <mileswjohn...@gmail.com> wrote:
> I found the problem, but cannot fix it. Its my afterFind() method for
> my Article model.
>
>         /**
>          * Executed after a find() call
>          */
>         function afterFind($results) {
>                 if (!empty($results)) {
>                         foreach ($results as &$result) {
>                                 if (is_array($result) && !empty($result['Article']['id'])) {
>                                         $result['Article']['favorites'] = $this->Favorites->find('count',
> array(
>                                                 'conditions' => array('Favorites.article_id' => $result
> ['Article']['id']),
>                                                 'contain' => false,
>                                                 'recursive' => -1
>                                         ));
>
>                                         $result['Article']['comments'] = $this->Comments->find('count',
> array(
>                                                 'conditions' => array('Comments.item_id' => $result['Article']
> ['id'], 'Comments.status' => 'approved'),
>                                                 'contain' => false,
>                                                 'recursive' => -1
>                                         ));
>                                 }
>                         }
>                 }
>
>                 return $results;
>         }
>
> Even when I disable contain and recursive, it still grabs all the
> extra data. BUT WHEN I remove the after find, the correct data is
> returned.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: