I am trying to figure out how to use containable properly. These are the model relationship: Client has many Account Account has many Bills Bills have many BillResources ResourceType hasMany BillResource BillResources belong to bill Bills belong to Account Account belongs to Client
I am trying to only return BillResources that have a resource_type_id = 2 So my query looks like CODE $this->Client->find('all', array( 'contain'=>array( 'Account' => array( 'conditions' => array('Account.client_id = '=>$this->Auth- >user('client_id')), 'fields' => array('id'), 'Bill' => array( 'fields' => array('id'), 'BillResource' => array( 'conditions' =>array( 'BillResource.resource_type_id =' => 1, ) ) ) ), ), 'conditions'=>array( 'Client.id' => $this->Auth->user('client_id'), ) ) ); However, the resulting array contains Bills with empty BillResources because the resource_type_id does not equal 1. How do I correctly query so that only Accounts with BillResource.resource_type_id = 1? (As you can see below Account[0] and Account[1] should not be returned) If a bill does not have a bill with the proper resource type it would not show up. If the account has no bills with the proper resource type the account should not be returned. Hope this was explained well...thanks in advance CODE Array ( [0] => Array ( [Client] => Array ( [id] => 3 [name] => foo ) [Account] => Array ( [0] => Array ( [id] => 6 [client_id] => 3 [Bill] => Array ( [0] => Array ( [id] => 32 [account_id] => 6 [BillResource] => Array ( ) ) [1] => Array ( [id] => 33 [account_id] => 6 [BillResource] => Array ( ) ) ) ) [1] => Array ( [id] => 7 [client_id] => 3 [Bill] => Array ( [0] => Array ( [id] => 36 [account_id] => 7 [BillResource] => Array ( ) ) [1] => Array ( [id] => 37 [account_id] => 7 [BillResource] => Array ( ) ) [2] => Array ( [id] => 38 [account_id] => 7 [BillResource] => Array ( ) ) ) ) [2] => Array ( [id] => 8 [client_id] => 3 [Bill] => Array ( [0] => Array ( [id] => 39 [account_id] => 8 [BillResource] => Array ( [0] => Array ( [id] => 60 [resource_type_id] => 1 ) ) ) [1] => Array ( [id] => 40 [account_id] => 8 [BillResource] => Array ( [0] => Array ( [id] => 61 [resource_type_id] => 1 ) ) ) [2] => Array ( [id] => 41 [account_id] => 8 [BillResource] => Array ( [0] => Array ( [id] => 62 [resource_type_id] => 1 ) ) ) [3] => Array ( [id] => 43 [account_id] => 8 [BillResource] => Array ( [0] => Array ( [id] => 64 [resource_type_id] => 1 ) ) ) [4] => Array ( [id] => 44 [account_id] => 8 [BillResource] => Array ( [0] => Array ( [id] => 65 [resource_type_id] => 1 ) ) ) [5] => Array ( [id] => 45 [account_id] => 8 [BillResource] => Array ( [0] => Array ( [id] => 66 [resource_type_id] => 1 ) ) ) ) ) ) ) ) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.