PostgreSQL fails when integer IDs are used in morph table
Laravel Version
v12.28.1
PHP Version
8.3.20
Database Driver & Version
PostgreSQL 10.22 up to latest
Description
PostgreSQL fails with this error when comparing an integer ID from the source table with the same ID stored as string value in versionable_id due to strict type comparison:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: character varying = integer
LINE 1: ...s_versions\" where \"cms_versions\".\"versionable_id\" in (6) and...
HINT: No operator matches the given name and argument types. You might need to add explicit type casts. (Connection: testing, SQL: select * from \"cms_versions\" where \"cms_versions\".\"versionable_id\" in (6) and \"cms_versions\".\"versionable_type\" = Aimeos\\Cms\\Models\\Page and \"cms_versions\".\"tenant_id\" = demo)
MySQL and SQLite don't show that problem because they don't enforce a strict type check when comparing values and are able to compare integer with string values using type conversion.
Steps To Reproduce
1.) create a source table with an integer ID column
2.) create a morph table
3.) create models for the source (Source) and morph table (Version)
4.) Define a morphTo relation (latest) in the Source model
5.) Fill in a record in the source table (id=1) and a corresponding value in the morph table (versionable_id='1', versionable_type='\App\Models\Source')
6.) Use Source::whereHas('latest')->get() to join the morph table