hasmanyのテーブルに対して条件を設定する方法

del_flg = 0のhasmanyテーブルを取得したい例

 

$this->[モデル名]->hasMany['関連モデル名']['conditions'] = '関連モデル名.del_flag = 0';

$data = $this->[モデル名]->findAll())

 

foreachを使えば、hasMany 内のテーブルが増えても大丈夫

 foreach ($this->hasMany as $k => &$v) { 

    $v['conditions'] = array(           

        $k . '.del_flg = 0',            

    );                                  

}

 

※結果のデータについては、あくまでhasManyのテーブル情報が空になるだけなので注意(left join のため)