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

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

Open
aausting opened this issue Jun 8, 2021 · 2 comments

Comments

@aausting
Copy link

aausting commented Jun 8, 2021

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
Copy link

envas commented Jul 10, 2021

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
Copy link
Member

@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 wintercms/winter#216 gets merged though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants