Hello guys,
Most of time we need to bind model at runtime, So cakephp provides inbuilt function
bindModel(). Using this function we can associates model according to requirement .
Using this technique we dont need to association in Model. It will bind model at the runtime and fetch data with association and also use recursive as per the requirement.
For Example:-
$this->Member->bindModel(
array(
'hasMany'=>array(
'NpoMember' =>array(
'className' => 'NpoMember',
'foreignKey' => 'member_id',
'conditions' => array('NpoMember.status' => 'Active'),
)
)
)
);
$this->NpoMember->bindModel(
array(
'belongsTo'=>array(
'Npo'=>array(
'className' => 'Npo',
'foreignKey' => 'npo_id',
'conditions' => array('Npo.status' => 'Active')
)
)
)
);
$userData = $this->Member->find('first',array('conditions'=>array('Member.email'=>$userEmail,'Member.password'=>$passWord,'Member.status'=>'Active')));
0 Comment(s)