admin管理员组文章数量:1393402
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.
本文标签: Laravel 10 Eloquent Morph fields type errorStack Overflow
版权声明:本文标题:Laravel 10 Eloquent. Morph fields type error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744624280a2616222.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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