1
2
3
4
5
6
7
8
9
10
11
12
13
|
module MetadataScopes
extend ActiveSupport::Concern
included do
scope :with_metadata, -> metadata {
where metadata.map{ |k, v| "metadata->>'#{k}' = '#{v}'"}.join(' AND ')
}
scope :has_metadata, -> key {
where "metadata ? '#{key}'"
}
end
end
|