here is my containable condition
$userStatusCondition = array('AND' => array(
'OR'=> array(
'TransactionStatus.buyer_status_id'=>$user_status_id,
'TransactionStatus.seller_status_id'=>$user_status_id,
)
)
);
Merge conditions (other conditions + user_status condition)
$transactions = $this->Transaction->find('all',array(
'conditions'=> Set::merge($otherConditions, $userStatusCondition),
'recursive'=>2));
in TransactionModel I set the
public $actsAs = array('Containable');
public $belongsTo = array(
'UserStatus' => array(
'className' => 'UserStatus',
'foreignKey' => 'buyer_status_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'UserStatus' => array(
'className' => 'UserStatus',
'foreignKey' => 'seller_status_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
);
problems
1) I don't like to use recursive 2: it decreases the find method - how ever I think after containable correctly I think I need to remove recursive
2) I have four user_statuses in User_Status table 1)waiting 2)attention 3)block 4)Complete which I want to find transactions filtered by buyer_status_id or seller_status_id
I donno how to create new behavior - there is small article about it Using Contain
Another way of linking to table relationship is to use bindModel to force Join.
Below is a code that binds 4 tables Items->Categories->Sections->divisions. You can find anything within the range of the relationship.
By doing this you can freely query anything in the range of the tables.
More Info here: http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations