Reputation: 816
Here is my scenario:
Here is my pagination code:
$this->paginate['Subfirm'] = array(
'contain' => array(
'Firm' => array(
'Firmtype',
'conditions' => $firmtype,
'Job' => array(
'Person'
),
'Attachment' => array(
'conditions' => array(
'Attachment.attachmentgroup_id' => 7
),
),
),
'Subfirmdetail' => array(
'Subfirmdetailtype' => array(
'Subfirmdetailoption',
),
),
'Substrategy'
),
'order' => array(
$order,
),
'conditions' => array(
'Subfirmdetail.value = 40',
),
);
return $this->paginate('Subfirm');
Let's say I want the Subfirmdetail.value to be 40, otherwise don't show the firm. This is the type of scenario I am trying to filter based on (or even deeper...). Been stuck for a while so any help would be appreciated!
Upvotes: 0
Views: 1004
Reputation: 6780
You need to use INNER Joins.
$joins = array(
array(
'table' => 'subfirmdetail',
'alias' => 'Subfirmdetail',
'type' => 'inner',
'conditions' => array( 'Subfirmdetail.value = 40', 'Subfirmdetail.subfirm_id = Subfirm.id' )
),
array(
'table' => 'subfirmdetailtype',
'alias' => 'Subfirmdetailtype',
'type' => 'inner',
'conditions' => array( 'Subfirmdetailtype.subfirmdetail_id = Subfirmdetail.id' )
),
array(
'table' => 'subfirmdetailoption',
'alias' => 'Subfirmdetailoption',
'type' => 'inner',
'conditions' => array( 'Subfirmdetailoption.subfirmdetailtype_id = Subfirmdetailtype.id' )
)
);
$this->paginate['Subfirm'] = array(
'fields' => array(
'Subfirmdetail.*', 'Subfirmdetailtype.*', 'Subfirmdetailoption.*'
),
'joins' => $joins,
'contain' => array(
'Firm' => array(
'Firmtype',
'conditions' => $firmtype,
'Job' => array(
'Person'
),
'Attachment' => array(
'conditions' => array(
'Attachment.attachmentgroup_id' => 7
),
),
),
'Substrategy'
),
'order' => array(
$order
)
);
return $this->paginate('Subfirm');
Upvotes: 2
Reputation: 540
You may want to use Linkable Bheavior for this: https://github.com/Terr/linkable
Upvotes: 0