我已经查看了有关此主题的所有线索,但没有解决我的问题。
我有一个'客户'表和一个'员工'表,应该通过'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
)
)
)
这里是对customers_employees的INSERT查询:
INSERT INTO `appsbf_db6`.`customers_employees` (`modified`, `created`) VALUES ('2012-07-26 06:40:22', '2012-07-26 06:40:22')
我的错误在哪里?
寻求帮助!
答案 0 :(得分:0)
请求数组中的Employee数据应如下所示:
[Employee] => Array
(
[0] => Array
(
[Employee] => Array
(
[first_name] = ADSF
.........
.........
)
)
[1] => Array
(
[Employee] => Array
(
[first_name] = wersdf
.........
.........
)
)
)
在您的视图中使用表单元素,如:
$this->Form->input('Employee.0.FirstName', array(...........
希望它对你有用。