“cakephp 3,保存不工作,未知类型”

问题描述 投票:0回答:1

这是我过去常用的链接CakePHP 3 Saving BelongsToMany Association Unknown type "" Error,但无法解决问题。

我有3张桌子:

  1. 预订
  2. 游客
  3. BookingsTravelers

当我将数据保存在预订表中时,我得到上面提到的错误,见下图:

模型关联看起来像这样:

public function initialize(array $config)
{
    parent::initialize($config);

    $this->table('bookings_travelers');
    $this->displayField('name');
    $this->primaryKey('bPassID');

    $this->belongsTo('Bookings', [
        'foreignKey' => 'booking_id',
        'joinType' => 'INNER'
    ]);
    $this->belongsTo('Travelers', [
        'foreignKey' => 'traveler_id',
        'joinType' => 'INNER'
    ]);
}

public function initialize(array $config)
{

    parent::initialize($config);

    $this->table('bookings');
    $this->displayField('idbooking');
    $this->primaryKey('idbooking');

    $this->belongsTo('Users', [
        'foreignKey' => 'user_id',
        'joinType' => 'INNER'
    ]);


    $this->belongsToMany('Travelers', [
        'joinTable' => 'bookings_travelers',
    ]);
}

public function initialize(array $config)
{
    parent::initialize($config);

    $this->table('travelers');
    $this->displayField('name');
    $this->primaryKey('travelers_id');


    $this->belongsToMany('Bookings', [
        'joinTable' => 'bookings_travelers',
    ]);
}
cakephp-3.0
1个回答
5
投票

基本上我只有在更改数据库列名后才能将'idbooking'重命名为'id',并且它有效。我的坏,一个愚蠢的错误。

© www.soinside.com 2019 - 2024. All rights reserved.