ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Ransack with serialized attributes not working on Rails 6

Open prasanthkrajan opened this issue 3 years ago • 1 comments

  • performing a ransack for serialized attributes on Rails 6 throws ActiveRecord::SerializationTypeMismatch error

Conference class model

class Conference < ActiveRecord::Base
    serialize :booked_location_uuids, Array
end
  • booked_location_uuids is a text type column in the conferences table

Example 1: When trying to do a ransack on collection of Conference for the serialized attribute booked_location_uuids

collection = Conference.all
search_params = {'booked_location_uuids_cont' => 'L02'}
collection.ransack(search_params).result

An error is thrown, and this occurs after upgrading to Rails 6:

can't dump `booked_location_uuids`: was supposed to be a Array, but was a String. -- "%L02%"` 

Example 2: using an array in the search params like this

collection = Conference.all
search_params = {'booked_location_uuids_cont' => ['L02']}
collection.ransack(search_params).result

throws the same error

ActiveRecord::SerializationTypeMismatch (can't dump `booked_location_uuids`: was supposed to be a Array, but was a String. -- "%[\"L02\"]%")

Ruby Version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin17] Rails Version: Rails 6.1.6 Ransack Version: ransack-3.2.1

prasanthkrajan avatar Jul 07 '22 05:07 prasanthkrajan

@prasanthkrajan what is the underlying database and can you please provide a copy of the schema.rb for the relevent table?

Or ... do a pull request with a failing test.

scarroll32 avatar Jul 20 '22 02:07 scarroll32