2011-04-22 3 views
1

나는 cakephp에 새로운 문제가있다. 나는 mysql에 2 개의 테이블을 만들었습니다. 내가 만들고자하는 관계는 'category_products'에 많은 'products'가 있습니다.CakePHP 도움말 : 나는 구울 수 없다.

CREATE TABLE category_products ( 
    id int NOT NULL PRIMARY KEY, 
    name varchar(30) NOT NULL 
) ENGINE=InnoDB; 

CREATE TABLE products ( 
    id int NOT NULL PRIMARY KEY, 
    name varchar(30) NOT NULL, 
    category_product_id int NOT NULL, 
    FOREIGN KEY (category_product_id) REFERENCES category_products(id) 
) ENGINE=InnoDB; 

내가 'category_products'를 구워 모든 괜찮지 만, 내가 콘솔에서 '제품'을 구울 때, 나는이 얻을 :

============================================================= 
Possible Models based on your current database: 
1. CategoryProduct 
2. Product 
Enter a number from the list above,type in the name of another model, or 'q' to exit  
[q] > 2 

Baking model class for Product... 
Creating file /opt/lampp/htdocs/caketest/app/models/product.php 
Wrote `/opt/lampp/htdocs/caketest/app/models/product.php` 
Product Model was baked. 
SimpleTest is not installed. Do you want to bake unit test files anyway? (y/n) [y] > n 

**Error: Missing database table 'categories' for model 'Category'** 

============================================================ 
Cakephp **doesn't create the view** and when i open the **model** for product.php and i see this at then end. 

var $belongsTo = array( 
     'CategoryProduct' => array( 
      'className' => 'CategoryProduct', 
      'foreignKey' => 'category_product_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 

var $hasAndBelongsToMany = array( 
     'Category' => array( 
      'className' => 'Category', 
      'joinTable' => 'category_products', 
      'foreignKey' => 'product_id', 
      'associationForeignKey' => 'category_id', 
      'unique' => true, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'finderQuery' => '', 
      'deleteQuery' => '', 
      'insertQuery' => '' 
     ) 
    ); 

내 문제는 내가 무슨 일을하고 있어요된다 ??? 분명히 cakephp는 내가 관계 HABTM을 만들려고한다고 생각합니다. cakephp를 사용하고 있습니다. 1.3.7

도와주세요. 감사!

답변

0

이것은 bake가 작동하도록 설계된 방법입니다. 당신은 데이터베이스에 제품이 있다는 것을 제외하면 아무 잘못도 없습니다. category_products는 HABTM이라고 생각합니다. 올바르게 작동하게하려면 몇 가지 옵션이 있습니다.

1- category_products를 굽기 전에 제품 테이블을 제거한 다음 수동으로 category_products에 관계를 추가하십시오.

2 굽는 동안 제품 테이블을 다른 것으로 변경 한 다음 모델로 돌아가서 이름과 관계를 Product로 업데이트합니다.

3- 오류를 무시하고 모델에서 HABTM 관계를 제거하십시오.

해피 코딩!