Issue
Here is the link CakePHP 3 Saving BelongsToMany Association Unknown type "" Error that I used to first, but could not solve the problem.
I have 3 tables:
- Bookings
- Travelers
- BookingsTravelers
When I save the data in the bookings table I get the error metioned above, see below image:
The models associations look like this:
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',
]);
}
Solution
Basically I had to rename the 'idbooking' to 'id' only after changing the database column name, and it worked. My bad, a silly mistake.
Answered By - Zaeem
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.