yeah the employee has a hasMany relationship with my Mistake table On Nov 16, 6:10 pm, Asmud <[email protected]> wrote: > Do you set-up the 'Employee' model, to have 'hasMany' association to > "Mistake" ...? If not, just set-up first then you won't need the > 'getMistakes' mistake. > And this to retrieve the mistake data by employee : $mistakes = > $this->Employee->Mistake->find('count'), just add array condition if you > > would like to retrieve mistake from specific employee. Hope this > help.... > > === Asmud === > > On Nov 17, 12:25 am, David Roda <[email protected]> wrote: > > > > > This ought to do it > > > function index(){ > > $employees = $this->paginate('Employee'); > > foreach ($employees as $employee) { > > $employee['Employee']['total_mistakes'] = > > $this->Employee->getMistakes($employee['Employee']['id']; > > } > > $this->set('employees', $employees); > > > } > > > I'm not exactly sure how your data is formed so you may have to modify the > > array indexes a bit. > > > hth, > > > Dave > > > On Mon, Nov 16, 2009 at 11:30 AM, genji <[email protected]> wrote: > > > Hey guys I have somewhat of a sticky situation here that I can't seem > > > to wrap my hands around. > > > > Here's the situation: At my job we've created a point of sale system > > > that the employees of the shops keep making mistakes at. > > > I am trying to create a a very simple application where we keep track > > > of the mistakes every employee make so we can make a bonus/punishment > > > system. > > > Here's where I'm stuck: I need to count the mistakes per employee and > > > display them(this should be done in the loop ofc). > > > > My tables: > > > employees > > > mistakes > > > shops > > > > The employee table only has the names of the employees and their > > > bonus. > > > The mistake table consists of the following: > > > id, date, description, employee_id, shop_id > > > > My employee model: > > > function getMistakes($employee){ > > > $total = $this->Mistake->find('count', array('conditions' => array( > > > 'Mistake.employee_id' => '2'))); > > > return $total; > > > } > > > > My employee controller: > > > function index(){ > > > $this->set('employees', $this->Employee->find('all')); > > > $this->set('employees', $this->paginate('Employee')); > > > $total = $this->Employee->getMistakes($employee); > > > $this->set('total_mistakes',$total); > > > } > > > > In my index.ctp the loop will go through each row in my employee table > > > and display the rows. > > > > I don't know how to achieve to count the mistakes WHERE > > > Mistake.empoyee_id == employee.id in my index.ctp > > > > Can anyone please help me? > > > Thanks in advance > > > > -- > > > > 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]<cake-php%[email protected] > > > om> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/cake-php?hl=.
-- 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=.
