2012-07-26 164 views
0

我已經查看了有關此主題的所有主題,但沒有任何方法可以解決我的問題。cakePHP HABTM不保存

我有一個'customers'表和一個'employees'表,應該通過'customers_employees'表連接。

在我的表單中,我可以選擇員工,但是當我想保存數據時,他只保存'創建'和'修改'條目,而不是鍵。

僱員有一個字符串id是CHAR(36)。

這是我在 '員工' 的模式進入:

public $hasAndBelongsToMany = array(
    'Customer' => array(
     'className' => 'Customer', 
     'joinTable' => 'customers_employees', 
     'foreignKey' => 'employee_id', 
     'associationForeignKey' => 'customer_id', 
     'unique' => 'keepExisting', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '', 
     'limit' => '', 
     'offset' => '', 
     'finderQuery' => '', 
     'deleteQuery' => '', 
     'insertQuery' => '' 
    ) 
); 

這是我的 '客戶' 的模式條目:

public $hasAndBelongsToMany = array(
    'Employee' => array(
     'className' => 'Employee', 
     'joinTable' => 'customers_employees', 
     'foreignKey' => 'customer_id', 
     'associationForeignKey' => 'employee_id', 
     'unique' => 'keepExisting', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '', 
     'limit' => '', 
     'offset' => '', 
     'finderQuery' => '', 
     'deleteQuery' => '', 
     'insertQuery' => '' 
    ) 
); 

請求數組是這樣的:

Array 
(
    [Customer] => Array 
     (
      [id] => 10000 
      [name] => XXXXX 
      [name2] => XXXXX 
      [address] => XXXXX 
      [address2] => 
      [country_code] => 
      [plz] => 12345 
      [place] => XXXXX 
      [tel] => XXXXX 
      [fax] => XXXX 
      [mail] => XXXXX 
      [customer_price_group] => XX 
      [allow_discount_line] => XX 
      [payment_code] => 0 
      [terms_of_delivery_id] => XXX 
      [closed] => 
      [uSt_IdNr] => DEXXXXXXXXX 
      [information] => 
      [conditions] => XX 
     ) 

    [Employee] => Array 
    (
     [Employee] => Array 
      (
       [0] => EMPXXX 
      ) 

    ) 

) 

這裏INSERT查詢給customers_employees:

INSERT INTO `appsbf_db6`.`customers_employees` (`modified`, `created`) VALUES ('2012-07-26 06:40:22', '2012-07-26 06:40:22') 

我的錯誤在哪裏?

Thx求助!在請求陣列

回答

0

你的員工的數據應該是這樣的:

[Employee] => Array 
(
    [0] => Array 
     (
      [Employee] => Array 
         (
          [first_name] = ADSF 
          ......... 
          ......... 
         ) 
     ) 

    [1] => Array 
     (
      [Employee] => Array 
         (
          [first_name] = wersdf 
          ......... 
          ......... 
         ) 
     ) 

) 

在您的視圖中使用表單元素,如:

$this->Form->input('Employee.0.FirstName', array(........... 

希望它會爲你工作。

+0

嗨,謝謝你的回答。但我需要的是一個列表,我可以選擇更多的客戶。 Cake生成了以下代碼:echo $ this-> Form-> input('Employee',array('label'=>'Mitarbeiter')); – 2012-08-01 06:37:14

+0

你應該嘗試使用:'echo $ this-> Form-> input('Employee] [',array('label'=>'Mitarbeiter'));' – 2012-08-06 05:25:18