Framework: belongsToMany relation custom primary key

Created on 22 Nov 2018  路  2Comments  路  Source: laravel/framework

  • Laravel Version: 5.7.14
  • PHP Version: 7.2
  • Database Driver & Version: PostgreSQL 10.6

Description:

class Univers extends Model
{
  use UuidForKey;
  use ImageCellar;

  public $incrementing = false;
  protected $guarded = [];
  protected $primaryKey = 'uuid';

  public function univers(){
    return $this->belongsToMany('App\Models\Context\Univers','univers_univers','univers_accessible_uuid','univers_origine_uuid');
  }
}

This code with laravel 5.7.7 working, but when i update laravel/framework to 5.7.14 I have an exception :

SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: character varying = integer\nLINE 1: ...id\" where \"univers_univers\".\"univers_accessible_uuid\" in (0)\n                                                                 ^\nHINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts. (SQL: select \"univers\".*, \"univers_univers\".\"univers_accessible_uuid\" as \"pivot_univers_accessible_uuid\", \"univers_univers\".\"univers_origine_uuid\" as \"pivot_univers_origine_uuid\" from \"univers\" inner join \"univers_univers\" on \"univers\".\"uuid\" = \"univers_univers\".\"univers_origine_uuid\" where \"univers_univers\".\"univers_accessible_uuid\" in (0)) 

It seems that in my relation it doesn't recognize my primary key type and try to parse it.

Most helpful comment

Check #26582.

All 2 comments

Check #26582.

Thanks it's working :)

Was this page helpful?
0 / 5 - 0 ratings