Cake 3保存belongToMany关系崩溃



我目前在两个表SkusMedias之间有一个belongsToMany关系。不过,我将联接表命名为skus_images。

我在这里试图只保存id,而不是以HABTM的方式插入新数据。我的表格中有:

echo $this->Form->input('images._ids', ['options' => $images, 'multiple' => 'checkbox']);

那里一切都很好,我正确地列出了我的媒体。但每当我试图提交表格时,我都会收到以下信息:

Error: Call to a member function get() on a non-object 
File /home/weshguillaume/AndyToGaby/vendor/cakephp/cakephp/src/ORM/Association/BelongsToMany.php 
Line: 874

我在SkusTable:中定义了我的关系

$this->belongsToMany('Images', [
     'className' => 'Media.Medias',
     'joinTable' => 'skus_images',
     'targetForeignKey' => 'image_id'
]);

上下文没有提供任何见解,堆栈跟踪也没有,因为它都(几乎)是空的。谢谢:)

编辑:控制器添加方法:

public function add($product_id)
    {
        $skus = $this->Skus->newEntity();
        if ($this->request->is('post')) {
            $skus = $this->Skus->patchEntity($skus, $this->request->data(), [
                'associated' => [
                    'Attributes'
                ]
            ]);
            if ($this->Skus->save($skus)) {
                $this->Flash->success('The skus has been saved.');
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error('The skus could not be saved. Please, try again.');
            }
        }
        $attributes = $this->Skus->Attributes->find('list');
        $images = $this->Skus->Products->getMedias('list', $product_id, 'photo');
        $this->set(compact('skus', 'products', 'attributes', 'images', 'product_id'));
        $this->set('_serialize', ['skus']);
    }

管制员公布数据:

[
    'product_id' => '65',
    'attributes' => [
        '_ids' => ''
    ],
    'reference' => '',
    'quantity' => '420',
    'is_default' => '0',
    'images' => [
        '_ids' => [
            (int) 0 => '90'
        ]
    ]
]

忘记在patchEntity associated选项中添加关联的名称。仍然不应该抛出致命错误,所以我创建了一个github票证。

最新更新