I'm having an issue where using a find in an afterFind callback is messing 
up my original contain.

*Short Story....

*When using this from my Note model:

$job = $this->Job->find('first', array(
    'conditions' => array('Job.id' => $data['Note']['job_id']),
    'contain' => array('Assignee', 'Project'),
));

All the Job's associated records are returned, not just those from 
Assignees and Projects. Removing Project form the contain array gives me 
what I would expect.

Now Project has an afterFind callback that runs this bit of code:

$job = $this->Job->find('first', array(
    'fields' => array('SUM(Job.cost) AS unbilled_total'),
    'conditions' => array('Job.project_id' => $result['Project']['id'], 
'Job.invoice_id IS NULL'),
    'contain' => false, //if Project is in the contain array we will get 
stuck in a loop
));

This seems to be what is causing the issue. Now, if i change the above code 
to the code below, it works:

App::uses('Job', 'Model');
$Job = new Job();

$job = $Job->find('first', array(
    'fields' => array('SUM(Job.cost) AS unbilled_total'),
    'conditions' => array('Job.project_id' => $result['Project']['id'], 
'Job.invoice_id IS NULL'),
    'contain' => false, //if Project is in the contain array we will get 
stuck in a loop
));

What seems to be happening is that when a callback is called that used the 
same model as the originating query then something is clashing and causing 
the contain to get messed up.

*Long Story...

*I'll add more about my project set up if needed, as i think the above may 
suffice.

My question is, is this how it should be done or was i right in doing it 
the way i did it first time, could this be a bug?

Cheers

-- 
Like Us on FaceBook 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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to