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.'conditions' => array('Job.id' => $data['Note']['job_id']),
'contain' => array('Assignee', 'Project'),
));
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
));
'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
));
$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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment