2011-09-08 11 views
0

私はCakePHPで衣装のディレクトリウェブサイトを作成しています。私は2つのモデル:StoreBrandを持っています。 BrandhasAndBelongsToManyとして設定されています。店舗には多くのブランドが関連付けられている可能性がありますが、明らかにブランドは多数の店舗に適用できます。hasAndBelongsToManyとして設定されているモデルを検索

私は自分のStoresController店舗を持っていますが、私が問題を抱えているのは、BrandsControllerのブランドリストを取得していることです。 BrandモデルのStoreモデルとhasAndBelongsToManyの関係を設定した場合、もはや$this->Brand->find('all')のようなことはできませんか?私はとき、私は次のエラーを取得する:ここで

Fatal error: Call to undefined method Brand::find() in /[path]/app/controllers/brands_controller.php on line 8

は私のモデルの定義です:

class Brand {  
    var $hasAndBelongsToMany = array(
     'Store' => array(
      'className' => 'Store', 
      'joinTable' => 'brands_stores', 
      'foreignKey' => 'brand_id', 
      'associationForeignKey' => 'store_id', 
      'unique' => true 
     ) 
    ); 
} 

そして、私のStoreモデル:

class Store extends AppModel { 
    var $hasMany = array(
     'Reviews' => array(
      'className' => 'StoreReview', 
      'foreignKey' => 'store_id', 
      'conditions' => array(
       'approved' => 1 
      ), 
      'order' => 'created DESC' 
     ) 
    ); 
} 

答えて

1

を拡張しますクラスブランドは、あなたが忘れてしまったようなAppModelを拡張する必要があります

+1

D'oh!ありがとう!あなたが深夜のコードを書くとどうなるのですか? –

2

クラスのブランドはのAppModel {