こんにちは。
cakephpを使用して、条件付きの値を取得したいのですが、うまくできずに困っています。
行いたいことは、hasMany でアソシエーションしている別モデル(下記例ではReserveモデル)の
カラムに対して条件を付けたいです。
lang
1// ベースモデル 2class Customer 3{ 4 var $hasMany = array( 5 'Reserve'=>array( 6 'className'=>'Reserve', 7 'foreignKey' => 'customer_id', 8 ) 9 ); 10} 11 12// サブモデル 13class Reserve { 14 .... 15} 16 17 18// コントローラー 19controller ... 20 21$condition = array( 22 'limit' => 20, 23 'order' => array('Customer.id DESC'), 24 'contain' => array( 25 'Reserve' 26 ), 27 ) 28); 29 30// ここに条件を追加したい 31/**ここから******************************************************/ 32 33// 行いたいこと 34上記の $condition の 'contain'しているモデルにwhere条件を付けたい 35SQLの例) 36select * from `Customer` 37join `Reserve` on `Customer`.id = `Reserve`.customer_id 38where `Reserve`.start >= NOW(); 39 40/**ここまで******************************************************/ 41 42$this->Customer = ClassRegistry::init('Customer'); 43$this->paginate=$condition; 44$data = $this->paginate('Customer'); 45

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。