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

BUG whereIn When PK != integer [HELP] #26603

Closed
jeffagostinho opened this issue Nov 23, 2018 · 4 comments
Closed

BUG whereIn When PK != integer [HELP] #26603

jeffagostinho opened this issue Nov 23, 2018 · 4 comments

Comments

@jeffagostinho
Copy link

  • Laravel Version: 5.7.14
  • PHP Version: 7.1
  • Database Driver & Version: PostgreSql

Description:

Hi guys,

I am developing a project where the requesting company asked for the table identifiers to be uuid (as much as I did not agree), so in my models I configured it like this

/ **
  * Indicates if the IDs are auto-incrementing.
  *
  * @var bool
  * /
public $ incrementing = false;
/ **
  * Boot uuid.
  *
  * @return void
  * /
public static function bootUuid ()
{
     static :: creating (function ($ model) {
         $ model -> {$ model-> getKeyName ()} = (string) Str :: uuid ();
     });
}

This worked until version 5.7.13, but now in 5.7.14 is giving the error

SQLSTATE [42883]: Undefined function: 7 ERROR: operator does not exist: uuid = integer

How can I get around this?

Thank you

Steps To Reproduce:

@CrixuAMG
Copy link

I just tried the same, but using a mysql database instead of PostgreSql, and it ran successfully.
A quick google resulted in the following page:

https://stackoverflow.com/questions/46433459/postgres-select-where-the-where-is-uuid-or-string

In the stackoverflow page they stated casting the column to uuid helped: uuid::uuid

@jeffagostinho
Copy link
Author

@CrixuAMG,

But because in the version of laravel 5.7.13 it works normally and in version 5.7.14 it does not? Would it be a database error?

@bonzai
Copy link
Contributor

bonzai commented Nov 23, 2018

#26582

Also, there's a note in the documentation:

Primary Keys

[…] If your primary key is not an integer, you should set the protected $keyType property on your model to string.

https://laravel.com/docs/5.7/eloquent#defining-models

@jeffagostinho
Copy link
Author

@bonzai, wow!

Thank you very much guy.

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