Item
이 Category
으로 분류되는 간단한 연관을 사용하고 있습니다. 동시에 Item
은 Brand
입니다. 지금까지 나는 엔티티가 3 개 있는데, Item
, Category
및 Brand
입니다. 예를 들어, 내 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(....
카테고리 또는 브랜드가 전혀 없습니다.
내가 뭘 잘못하고 있니?
이 그것을 해결, 감사와
저장됩니다 –$hasOne
을 변경해야합니다