Skip to content

Instantly share code, notes, and snippets.

@tlux
Last active December 19, 2015 00:09
Show Gist options
  • Select an option

  • Save tlux/5866655 to your computer and use it in GitHub Desktop.

Select an option

Save tlux/5866655 to your computer and use it in GitHub Desktop.
Query for serialized fields
class ProductAttribute < ActiveRecord::Base
# ...
serialize :value
class << self
def with_value(value)
dumped_value = serialized_attributes['value'].dump(value)
where(value: dumped_value)
end
def without_value(value)
dumped_value = serialized_attributes['value'].dump(value)
where('value != ?', dumped_value)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment