cakephp - 嵌套数据上的 saveAll()

标签 cakephp nested associations cakephp-2.0

当我尝试使用 $data 数组创建模板的新条目时,模板、组和产品的模型已正确保存。但是嵌套的Calcfield(它是一个hasMany of Group)不会被保存。 :( 组和产品有很多模板。

这可能吗?

$this->Template->create();
$this->Template->saveAll($data, array('validate' => false));

// $data looks like this:

Array
(
    [Template] => Array
        (
            [title] => 
            [shorttitle] => Wie auch immer
            [place] => Hannover
            [size] => 
        )

    [Group] => Array
        (
            [0] => Array
                (
                    [title] => Hosting
                    [order] => 
                    [Calcfield] => Array
                        (
                            [0] => Array
                                (
                                    [title] => Hosting
                                    [value] => 0
                                    [description] => 
                                )
                            [1] => Array
                                (
                                    [title] => Strom
                                    [value] => 0
                                    [description] => 
                                )
                        )
                )
        )

    [Product] => Array
        (
            [0] => Array
                (
                    [share] => 10
                    [businessunit] => Marketing
                )
            [1] => Array
                (
                    [share] => 30
                    [businessunit] => intl. CRM
                )
        )
)

最佳答案

不,据我所知,递归保存是不可能的。您需要将它们粘贴在单独的数组中,然后在初始保存后保存它们。

关于cakephp - 嵌套数据上的 saveAll(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9098084/

相关文章:

没有页眉/页脚的 CakePHP 页面

cakephp 为什么我不能有管理员路由和 super 用户路由?

cakephp - 如何让 CakePHP 呈现带换行的纯文本?

node.js - 在 mongoDB 中的嵌套记录中查找(通过引用 ObjectId 嵌套)

css - 将自定义类添加到 CakePHP 自动日期选择

ruby-on-rails - Ruby 嵌套数组迭代复杂度

javascript - 访问父 Controller 重复的当前实例

ruby-on-rails - Arel 和多态关联连接

go - 协会不使用测试条目

associations - 如何再次将某个文件类型与 "View file"关联