Let's take the simple example of a blog with:
- A post
habtm
tags - A tag
habtm
posts
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query | |
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails | |
#payload: [{"kind"=>"person"}] | |
Segment.where("payload @> ?", [{kind: "person"}].to_json) | |
#data: {"interest"=>["music", "movies", "programming"]} | |
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json) | |
Segment.where("data #>> '{interest, 1}' = 'movies' ") | |
Segment.where("jsonb_array_length(data->'interest') > 1") |
# add this into application.rb | |
initializer_file = Rails.root.join('config', 'initializers', 'my_initializer.rb') | |
reloader = ActiveSupport::FileUpdateChecker.new([initializer_file]) do | |
load initializer_file | |
end | |
ActiveSupport::Reloader.to_prepare do | |
reloader.execute | |
end |
.git | |
.gitignore | |
/doc | |
.yardoc | |
coverage | |
jsdoc | |
/tmp | |
/log | |
Dockerfile | |
Dockerfile.prod |
require "set" | |
class Proc | |
def self.register_type(klass, proc) | |
@types_to_convert ||= {} | |
@types_to_convert[klass] = proc | |
end | |
def self.[](field) | |
-> (x) { (@types_to_convert || {})[field.class].call(field, x) } |