这是我过去常用的链接CakePHP 3 Saving BelongsToMany Association Unknown type "" Error,但无法解决问题。
我有3张桌子:
当我将数据保存在预订表中时,我得到上面提到的错误,见下图:
模型关联看起来像这样:
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',
]);
}
基本上我只有在更改数据库列名后才能将'idbooking'重命名为'id',并且它有效。我的坏,一个愚蠢的错误。