So apparently the find('all'... with 'limit = 1' does not work and is a bug
in 2.2. I changed to the following query, and now it works fine...
$reply = $this->find('first', array(
'conditions' => array(
'Post.deleted !=' => 1,
'Post.replyto_post_id' => $id),
'fields' => array('PostedBy.tag', 'Post.activitydate'),
'order' => array('activitydate DESC')
));
On Tuesday, September 25, 2012 10:12:37 AM UTC-4, d6games wrote:
>
> Here is the code. Can you see what I'm doing wrong? In the afterFind
> callback, the first replyCount() function call is working just fine, but
> the subsequent call to lastReply() never returns anything and I don't know
> why. I can look at the data in MySQL tables and see the data that should be
> coming back. Is there some issue with calling to private Model functions
> from each afterFind?
>
> //
> -----------------------------------------------------------------------------
> // PRIVATE FUNCTIONS
> private function replyCount($id) {
> return $this->find('count', array(
> 'conditions' => array(
> 'Post.deleted !=' => 1,
> 'Post.replyto_post_id' => $id
> )
> ));
> }
>
> private function lastReply($id) {
> $reply = $this->find('all', array(
> 'conditions' => array(
> 'Post.deleted !=' => 1,
> 'Post.replyto_post_id' => $id),
> 'order' => array('activitydate DESC'),
> 'limit' => 1
> ));
> $returnVal = "";
> if ( count($reply) > 0 ) {
> $returnVal = $reply['PostedBy']['tag']."<br
> /><small>".$reply['Post']['activitydate']."</small>";
> }
> return $returnVal;
> }
>
> //
> -----------------------------------------------------------------------------
> // CALLBACKS
> public function afterFind($results, $primary = false) {
> parent::afterFind($results,$primary);
> foreach ($results as $key => $val) {
> if (isset($val['Post']['id'])) {
> $results[$key]['Post']['replies'] =
> $this->replyCount($val['Post']['id']);
> $results[$key]['Post']['lastreply'] =
> $this->lastReply($val['Post']['id']);
> }
> }
> return $results;
> }
>
>
>
>
>
--
Like Us on FacekBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
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].
Visit this group at http://groups.google.com/group/cake-php?hl=en.