【发布时间】:2013-11-28 16:30:32
【问题描述】:
我正在尝试保存数组 $sales。
这里将数据放入这个数组中:
sales
0
Product
id146
category
descriptiondrei
created2013-11-20 14:10:12
modified2013-11-20 14:10:12
shop_id27
category_id1
image(null)
Shop
id27
user_id23
titlebarby
descriptionkleines
created2013-10-29 12:51:32
modified2013-10-29 12:51:32
Category
id1
imageHaushalt
Controller 中的方法如下所示:
公共函数 save_notepad() {
$sales = array();
if($this -> Session -> valid() && $this -> Session -> check('notepad')) {
$notepad = $this -> Session -> read('notepad');
$this->loadModel('Product');
$condition = array('Product.id' => $notepad);
$sales = $this -> Product-> find('all', array('conditions' => $condition));
}
$this -> set('sales', $sales);
if ($this->request->is('post')) {
$this->Sale->create();
if ($this->Sale->saveall($sales));
$this->Session->setFlash(__('The sale has been saved'));
return $this->redirect(array('action' => 'index'));
}
}
问题是,当我保存时,在数据库中它只保存 id 和创建日期。
模型如下所示: 类销售扩展 AppModel {
public $belongsTo = array(
'Product' => array(
'className' => 'Product',
'foreignKey' => 'product_id',
'conditions' => array('Product.id' => 'Sale.product_id'),
'fields' => '',
'order' => ''
),
'Shop' => array(
'className' => 'Shop',
'foreignKey' => 'shop_id',
'conditions' => '',
'fields' => '',
'order' => ''
));
}
我需要做些什么来保存数组 $sales 中已经存在的“product_id”和“shop_id”?
感谢您的帮助!
【问题讨论】:
标签: cakephp