Wednesday, November 19, 2014

Re: hasMany and find()

$this->Parent->recursive = -1;
$options['fields'] = array(
        'Parent.id',
        'Parent.name',
      );
      $options['limit'] = 10000;
      $options['joins'] = array(
        array(
          'type' => 'LEFT',
          'alias' => 'Children',
          'table' => 'children',
          'conditions' => array('Parent.id = Children.parent_id')));
 
      $options['conditions'] = array(
        'Children.name IS NULL'
      );
      $parent_with_no_child = $this->Parent->find('all', $options);

Solved it myself.

--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: