我正在使用蛋糕 PHP 2.x。我的数据库是这样设置的。
评级有一条评论
评论有很多照片
data => array(
'Rating' => array(
'rating' => '1',
'user_id' => '1',
'listing_id' => '55'
),
'Review' => array(
'title' => 'Good Service',
'date_visited' => array(
'month' => '05',
'day' => '28',
'year' => '2013',
),
'service_used' => 'Easy Checkout',
'description' => 'After a fairly quick check-in, the check out service was also breeze ',
'Photo' => array(
(int) 1 => array(
'title' => 'Test',
'photo' => array(
'name' => '2.JPG',
),
'listing_id' => '55',
'user_id' => '1'
)
)
)
)
审查.php
public $hasMany = array(
'Photo' => array(
'className' => 'Photo',
'conditions' =>'',
'order' => ''
)
);
照片.php
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Review' => array(
'className' => 'Review',
'foreignKey' => 'review_uuid',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Listing' => array(
'className' => 'Listing',
'foreignKey' => 'listing_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
最后是 RatingsController.php
$this->Rating->create();
if ($this->Rating->saveAll($this->request->data, array('deep' => true))) {
$this->Session->setFlash(__('The rating has been saved'));
$this->redirect(array('action' => 'index'));
}
问题是所有数据都被保存了,除了照片模型中的 review_uuid (也正在同时创建))。
mysql> select id,user_id,listing_id,review_uuid,title,photo,photo_dir from photos where ID=26;
+----+---------+------------+-------------+-------+--------------------------------------+----------- +
| id | user_id | listing_id | review_uuid | title | photo | photo_dir |
+----+---------+------------+-------------+-------+--------------------------------------+----------- +
| 26 | 1 | 55 | NULL | Test | 1a107372ef53ba26d7748a50c25e6b27.jpg | 01/77/74 |
+----+---------+------------+-------------+-------+--------------------------------------+-----------+