Monday, October 27, 2008

How to filter a model that is using a hasMany?

Hi,

Let's say I have the following models.

class User extends AppModel {
var $name="User";
var $hasMany=array('Document');
}

class Document extends AppModel {
var $name="Document";
}

Now some Users have published documents, and some Users have not. So I
want to create a SQL condition that will only find all the Users who
have some Documents, but ignore Users who have none.

I can't figure out the condition for this. Everything I try produces a
SQL error.

$data = $this->User->find('all',array('conditions'=>array(????)));
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: