繁体   English   中英

蛋糕3的保存AboutToMany关系崩溃

[英]Cake 3 saving belongsToMany relation crashes

我目前在两个Table, SkusMedias之间有一个EmiratesToMany关系。 我将连接表命名为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票。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM