cakephp使用saveAll保存多个hasmany相关模型

时间:2014-03-01 15:42:44

标签: php cakephp cakephp-2.0

我整天都在搜索答案,但还是找不到解决办法。有人能找出问题所在吗?

我的数据关系表如下:

class Client extends AppModel{
public $hasMany = array('Order' => array('className' => 'Order', 'primaryKey' => 'client_id'));
}

class Order extends AppModel {
    public $hasMany = array('OrderItem'=>array('className'=>'OrderItem','primaryKey'=>'order_id'));

}

class OrderItem extends AppModel {
    public $useTable='orderitems';
    public $hasMany = array('OrderItem_Supplement'=> array('className' => 'OrderItem_Supplement', 'primaryKey' => 'orderitem_id'));

}

class OrderItem_Supplement extends AppModel{
    public $useTable = 'orderitem_supplements';
}

这是我想用saveAll($this->request->data,array('deep'=>true));

保存的数据的print_r()
Array
(
    [Order] => Array
        (
            [payment_method] => paypal
            [delivery_time] => 16:25
            [comment] => this is a test information
            [status] => checkout
        )

    [Client] => Array
        (
            [name] => person name
            [address] => address 
            [housenr] => 21
            [postcode] => 45332
            [town] => New York
            [email] => perosn@email.com
            [tel] => 94338493303298
        )

    [OrderItem] => Array
        (
            [0] => Array
                (
                    [orderitem] => Array
                        (
                            [price] => 4.00
                            [name] => Dagverse Groenten Soep
                            [vat_percent] => 12
                            [qty] => 6
                            [item_id] => 1
                        )

                    [OrderItem_Supplement] => Array
                        (
                            [0] => Array
                                (
                                    [supplement_id] => 1
                                    [qty] => 5
                                    [price] => 12.5
                                    [name] => Naan
                                )

                            [1] => Array
                                (
                                    [supplement_id] => 2
                                    [qty] => 5
                                    [price] => 15
                                    [name] => Kaas
                                )

                        )

                )

            [1] => Array
                (
                    [orderitem] => Array
                        (
                            [price] => 12.00
                            [name] => Kip Momo
                            [vat_percent] => 12
                            [qty] => 5
                            [item_id] => 2
                        )

                    [OrderItem_Supplement] => Array
                        (
                        )

                )

        )

)

0 个答案:

没有答案