【发布时间】:2011-04-26 19:46:09
【问题描述】:
我正在尝试保存订单以及订单中的产品。
订单正在保存,但产品未保存。
我有一个orders 表和一个products 表和一个orders_products 表。
在我设置的订单模型$hasAndBelongsToMany = 'Product';
在orders_products 表上,我有几个额外的字段:order_id、product_id 加上price、quantity 以获取销售价格和销售数量。
我正在通过以下方式保存数据:
$this->Order->saveAll($data);
$data 是这样的:
Array
(
[Order] => Array
(
[user_email] => st@kr.com
[billing_first] => Steve
... //more excluded
[total] => 5000
)
[Product] => Array
(
[0] => Array
(
[id] => 1
[price] => 5000.00
[quantity] => 1
)
)
)
订单保存到 order 表中,但没有保存到 orders_products 表中。我预计orders_products 表将保存[new_order_id], 1, 5000.00, 1
我确实收到了这条通知:
Notice (8): Undefined index: id [CORE/cake/libs/model/model.php, line 1391]
Model::__saveMulti() - CORE/cake/libs/model/model.php, line 1391
Model::save() - CORE/cake/libs/model/model.php, line 1355
Model::__save() - CORE/cake/libs/model/model.php, line 1778
Model::saveAll() - CORE/cake/libs/model/model.php, line 1673
CartsController::saveOrder() - APP/controllers/carts_controller.php, line 128
CartsController::checkout() - APP/controllers/carts_controller.php, line 172
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83
有什么想法吗?
【问题讨论】:
标签: php mysql cakephp cakephp-1.3