lib/dynamoid/criteria/chain.rb in dynamoid-1.3.0 vs lib/dynamoid/criteria/chain.rb in dynamoid-1.3.1
- old
+ new
@@ -3,13 +3,14 @@
module Criteria
# The criteria chain is equivalent to an ActiveRecord relation (and realistically I should change the name from
# chain to relation). It is a chainable object that builds up a query and eventually executes it by a Query or Scan.
class Chain
+ # TODO: Should we transform any other types of query values?
+ TYPES_TO_DUMP_FOR_QUERY = [:string, :integer, :boolean]
attr_accessor :query, :source, :values, :consistent_read
include Enumerable
-
# Create a new criteria chain.
#
# @param [Class] source the class upon which the ultimate query will be performed.
def initialize(source)
@query = {}
@@ -28,10 +29,17 @@
# @example A more complicated criteria
# where(:name => 'Josh', 'created_at.gt' => DateTime.now - 1.day)
#
# @since 0.2.0
def where(args)
- args.each {|k, v| query[k.to_sym] = v}
+ args.each do |k, v|
+ sym = k.to_sym
+ query[sym] = if (field_options = source.attributes[sym]) && (type = field_options[:type]) && TYPES_TO_DUMP_FOR_QUERY.include?(type)
+ source.dump_field(v, field_options)
+ else
+ v
+ end
+ end
self
end
def consistent
@consistent_read = true