저는 CakePHP로 의류 디렉토리 웹 사이트를 만들고 있습니다. 두 모델이 있습니다 : Store
및 Brand
. Brand
은 hasAndBelongsToMany
으로 설정되었으므로 상점과 관련된 많은 브랜드가있을 수 있지만 분명히 브랜드는 수많은 상점에 적용될 수 있습니다.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'
)
);
}
D' oh! 감사! 늦은 밤에 코드가 생기면 어떻게 될까요? –