【问题标题】:Saving belongsToMany associations in CakePHP 3在 CakePHP 3 中保存 belongsToMany 关联
【发布时间】:2015-04-02 12:30:35
【问题描述】:

我在保存 belongsToMany 关联时遇到了一个问题,并且正在保存的数据是现有实体和新实体的组合。

数据数组如下:

$data = [
    'tags' => [
        ['label' => 'Some new tag'],
        ['label' => 'Another new tag'],
        '_ids' => [1, 2] 
    ]
];

是不是这两种保存这个关联的方法不能一起用?

我尝试创建一个数据数组,其中每个实体都是它自己的数组项,如下所示:

$data = [
    'tags' => [
        ['label' => 'Some new tag'],
        ['label' => 'Another new tag'],
        ['id' => 1], 
        ['id' => 2] 
    ]
];

但是当它只是 ids 时,这不会创建新的关联。我是否需要先处理新实体的创建,然后使用 ['_ids'] 方法创建关联,还是我的数据数组有问题?

【问题讨论】:

  • 你可以给你看.ctp表格吗?
  • 我编译了表格中的数据数组,因为它不是一个直截了当的形式。

标签: php cakephp model save associations


【解决方案1】:

在此次提交https://github.com/cakephp/cakephp/commit/0333639025780d2400b1888d0a2d1cab6c76d37a 时,现在可以使用 seconds $data 数组结构。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多