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求助!在请求阵列
嗨,谢谢你的回答。但我需要的是一个列表,我可以选择更多的客户。 Cake生成了以下代码:echo $ this-> Form-> input('Employee',array('label'=>'Mitarbeiter')); – 2012-08-01 06:37:14
你应该尝试使用:'echo $ this-> Form-> input('Employee] [',array('label'=>'Mitarbeiter'));' – 2012-08-06 05:25:18