如何创建加入 table 记录

How to create a join table record

所以我想在我的连接中添加一条记录 table,但它似乎不起作用,也没有给出任何错误。

这是我的数据数组(正确保存没有问题)

array(3) {
    ["id"]=>
    string(2) "32"
    ["title"]=>
    string(5) "Hello"
    ["participant"]=>
    array(1) {
    [0]=>
        array(1) {
          ["id"]=>
          int(1)
        }
      }
}

我属于很多人:

$this->belongsToMany('Participants', [
        'foreignKey' => 'item_id',
        'targetForeignKey' => 'participant_id',
        'className' => 'Users',
        'joinTable' => 'participants_items'
    ]);

属于我的许多用户:

$this->belongsToMany('myItems', [
        'foreignKey' => 'participant_id',
        'targetForeignKey' => 'item_id',
        'className' => 'Items',
        'joinTable' => 'participants_items'
    ]);

以下方法我试过应用加入table记录:

$data['Participants'] = [ //Also tried Participant, participants, participant
    ['id' => 1]
];

还有:

$data['Participants'] = [
    '_ids' => [1, 2]
];

我做错了什么?我没有收到任何错误和条目

我发现我的错误实际上是在 newEntity() 部分!

之前(损坏):$newEntity = $this->newEntity($inputData]);

之后(固定):$newEntity = $this->newEntity($inputData, ['associated' => ['Participants']])

在执行 newEntity 之前,我将 id 添加到数据列表中,如下所示:

$inputData['participants'] = [
    '_ids' => [10, 12]
];