I have a simple hasMany relationship set up with CakePHP and I want to
retrieve a couple of fields from the parent table based on the count
of the child.
The scenario: I have boxes that hold 81 aliquots each. (Each box is
9X9.) I want to retrieve the id and description from the boxes table
of boxes that have fewer than 81 aliquots to generate a list. In other
words, I want a list of boxes that are not full.
My models:
class Box extends AppModel {
var $name = 'Box';
var $hasMany = array('Aliquot');
var $belongsTo = 'Freezer';
}
class Aliquot extends AppModel
{
var $name = 'Aliquot';
var $belongsTo = array('Box','Specimen');
}
I can't seem to work out the best way to get a count of the aliquots
for each box. I haven't been working with CakePHP all that long, so
I'm hoping there's a relatively simple way to do this that I'm
missing. It doesn't seem like a very complicated thing to do, yet I've
spent the better part of my morning working on it with not success.
This seems like it would work:
http://book.cakephp.org/view/75/Saving-Your-Data#counterCache-Cache-your-count-490
Except that my tables are already populated, so creating the
aliquot_count field in my boxes table just leaves me with a bunch of
empty fields. Does anyone have some advice that will point me in the
right direction?
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---