Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

belongsToMany relation custom primary key #26591

Closed
hyosh opened this issue Nov 22, 2018 · 2 comments
Closed

belongsToMany relation custom primary key #26591

hyosh opened this issue Nov 22, 2018 · 2 comments

Comments

@hyosh
Copy link

hyosh commented Nov 22, 2018

  • 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.

@bonzai
Copy link
Contributor

bonzai commented Nov 22, 2018

Check #26582.

@hyosh
Copy link
Author

hyosh commented Nov 22, 2018

Thanks it's working :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants