PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 31, 2021

[FIXED] "cakephp 3, save not working, Unknown type"

 December 31, 2021     cakephp-3.0     No comments   

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:

  1. Bookings
  2. Travelers
  3. BookingsTravelers

When I save the data in the bookings table I get the error metioned above, see below image:

enter image description here

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing