I`m using postgres 17.2
I have transactions table with morph columns entity_type and entity_id. When i use whereHasMorph i got a type error with entity_id because users table id is bigint
Example:
$query->whereHas('user', function (Builder $query) use ($dto) {
$query->whereRaw("id = ?", [$dto->sender])
->orWhereRaw("username = ?", [$dto->sender]);
});
$query->whereHasMorph('entity', [EntityTypeEnum::USER->value], function (Builder $query) use ($userId) {
$query->whereRaw("id = ?", [$userId]);
});
return;
Output Error:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: character varying = bigint\n
LINE 1: ...users" where "payment"."transactions"."entity_id" = "account...\n
^\n
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
What to do in this situation, how to fix the error in types without using raw sql
Chat gpt dont give me any working solutions
I`m using postgres 17.2
I have transactions table with morph columns entity_type and entity_id. When i use whereHasMorph i got a type error with entity_id because users table id is bigint
Example:
$query->whereHas('user', function (Builder $query) use ($dto) {
$query->whereRaw("id = ?", [$dto->sender])
->orWhereRaw("username = ?", [$dto->sender]);
});
$query->whereHasMorph('entity', [EntityTypeEnum::USER->value], function (Builder $query) use ($userId) {
$query->whereRaw("id = ?", [$userId]);
});
return;
Output Error:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: character varying = bigint\n
LINE 1: ...users" where "payment"."transactions"."entity_id" = "account...\n
^\n
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
What to do in this situation, how to fix the error in types without using raw sql
Chat gpt dont give me any working solutions
Share Improve this question asked Mar 15 at 3:17 EyeVersEyeVers 1 1 |1 Answer
Reset to default 0Your issue arises because in your transactions
table, entity_id
is likely stored as a VARCHAR
(or TEXT
), whereas the id
column in the users
table is of type BIGINT
. PostgreSQL does not automatically cast VARCHAR
to BIGINT
when comparing them in a WHERE
clause.
character varying = bigint
in the error tells us that somewhere in the query a text value is being compared with a number, which it does not like. My guess is thatentity_id
is the bigint value and theaccount...
something is text? – JorisJ1 Commented Mar 16 at 13:44