2014-01-17 1 views
0

ItemCategory으로 분류되는 간단한 연관을 사용하고 있습니다. 동시에 ItemBrand입니다. 지금까지 나는 엔티티가 3 개 있는데, Item, CategoryBrand입니다. 예를 들어, 내 Item 테이블에 나는 category_id = 1, brand_id = 1을 가지고있었습니다.cakePHP 연관 데이터 형식 add

echo $this->Form->input('name'); 
echo $this->Form->input('description'); 
//... 
echo $this->Form->input('Category'); 
echo $this->Form->input('Brand'); 

문제가 있다는 것입니다보기에서 컨트롤러

public function add() { 
    $this->set('categories', $this->Item->Category->find('list')); 
    $this->set('brands', $this->Item->Brand->find('list')); 
    //... 

에서

class Item extends AppModel { 
    public $hasOne = array('Category','Brand'); 
} 

:

그래서, 문서를 읽고, 나는 다음을 수행해야 함을 이해 MySQL 쿼리가 시도를 실행하여 name, description 인 행을 만들었지 만 카테고리는 만들지 않았습니다. y 또는 브랜드. INSERT INTO Item('name',description') VALUES(.... 카테고리 또는 브랜드가 전혀 없습니다.

내가 뭘 잘못하고 있니?

답변

1

당신은 레이블 이름은 여전히 ​​CategoryBrand을 될 것

echo $this->Form->input('category_id'); 
echo $this->Form->input('brand_id'); 

로 변경해야하지만 값은 또한 $belongsTo = array('Category','Brand');

+0

이 그것을 해결, 감사와 $hasOne을 변경해야합니다

저장됩니다 –