2011-09-08 5 views
0

저는 CakePHP로 의류 디렉토리 웹 사이트를 만들고 있습니다. 두 모델이 있습니다 : StoreBrand. BrandhasAndBelongsToMany으로 설정되었으므로 상점과 관련된 많은 브랜드가있을 수 있지만 분명히 브랜드는 수많은 상점에 적용될 수 있습니다.hasAndBelongsToMany로 설정된 모델에서 찾기

나는 내 StoresController 상점을 가져 오는 것이지만, 문제가되는 것은 내 BrandsController에있는 브랜드 목록을 가져 오는 것입니다. 내 Brand 모델이 내 Store 모델과 hasAndBelongsToMany 관계를 갖도록 설정 한 경우 더 이상 $this->Brand->find('all')과 같은 작업을 수행 할 수 있습니까?

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이 확장을 여기

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

내 모델 정의입니다 : 내가 할 때 나는 다음과 같은 오류가 발생합니다 클래스 브랜드는 AppModel을 확장해야합니다. 잊어 버린 것 같습니다.

+1

D' oh! 감사! 늦은 밤에 코드가 생기면 어떻게 될까요? –

2

클래스 브랜드 {

관련 문제