Here is the table structure
create_table :audits, :force => true do |t|
t.column :audited_changes, :text
end
class Audit < ::ActiveRecord::Base
serialize :audited_changes, Hash
end
This is bunch of code from gem Audited gem where I need to query text field audited_changes which is stored as serialized hash.
Found a reference where we can query for serialized array in text Searching serialized data, using active record, Do I have any option similar to that for querying rather that looping tons of records?
This is how I'm taking out the records I need from a audited_changes
fields = ['name', 'description']
audit_data = audit_data.select do |obj|
obj.define_singleton_method(:audited_changes_filtered) do
obj.audited_changes.select {|k,v| fields.map(&:to_s).include?(k) }
end
obj if fields_present?(obj, fields)
end