wintercms / wn-blog-plugin

Blog plugin for Winter CMS
https://wintercms.com/
MIT License
18 stars 24 forks source link

PostgreSQL: Misconfigured 'Winter\Blog\Models\Post' featured_images relation? #16

Open aausting opened 3 years ago

aausting commented 3 years ago

Hi, i figured out a possible misconfiguration of the 'Winter\Blog\Models\Post' featured_images relation. Postgresql reports the following error:

STATEMENT:  select * from "system_files" where "system_files"."attachment_id" in (1) and "system_files"."attachment_type" = $1 and "field" = $2 order by "sort_order" asc

The IN part of the query fails cause of incompatible types (string / integer).

Adding a cast expression seems to fix this error:

'featured_images' => ['System\Models\File', 
  'key' => 'CAST (attachment_id as integer)', 
  'order' => 'sort_order'
],

I did not check, if this query works in mysql.

envas commented 3 years ago

I made a quick test and I can commit the fix works on MySQL database.

I run into this error after migrating OctoberCMS to WinterCMS, it was interesting that on the OctoberCMS build 472 the generated statement worked fine without casting => Laravel 6.x?

LukeTowers commented 3 years ago

@envas that's because of some changes made in Laravel 6+ where the keyType can be defined and the type of the attachment_id is technically a varchar (string) but Laravel thinks it's an integer. There was a fix for this in October 1.1.x, but I believe it was reverted because it caused some other issues. It will be fixed properly in Winter once https://github.com/wintercms/winter/pull/216 gets merged though.