Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for #528. Updates how custom types are dumped in Query.

* If a query involves a custom type, the property value must be dumped via the custom type API.
* Query's with custom types in a Query::Path are handled as a special case.
  • Loading branch information...
commit 4fbeca8d8b3d7c1207974e91f51229b9a6bf8b20 1 parent 4f84ce8
@benburkert benburkert authored
Showing with 17 additions and 13 deletions.
  1. +17 −13 lib/dm-core/query.rb
View
30 lib/dm-core/query.rb
@@ -189,8 +189,6 @@ def initialize(repository, model, options = {})
@links = normalize_links(@links)
@includes = normalize_includes(@includes)
- translate_custom_types(@properties, options)
-
# treat all non-options as conditions
(options.keys - OPTIONS - OPTIONS.map { |option| option.to_s }).each do |k|
append_condition(k, options[k])
@@ -218,17 +216,6 @@ def initialize_copy(original)
@conditions = original.conditions.map { |tuple| tuple.dup }
end
- def translate_custom_types(properties, options)
- options.each do |key, value|
- case key
- when DataMapper::Query::Operator
- options[key] = properties[key.target].type.dump(value, properties[key.target]) if properties.has_property?(key.target) && properties[key.target].custom?
- when Symbol, String
- options[key] = properties[key].type.dump(value, properties[key]) if properties.has_property?(key) && properties[key].custom?
- end
- end
- end
-
# validate the options
def assert_valid_options(options)
# validate the reload option and unique option
@@ -440,9 +427,26 @@ def append_condition(clause, bind_value)
raise ArgumentError, "Clause #{clause.inspect} does not map to a DataMapper::Property", caller(2)
end
+ bind_value = dump_custom_value(property, bind_value)
+
@conditions << [ operator, property, bind_value ]
end
+ def dump_custom_value(property_or_path, bind_value)
+ case property_or_path
+ when DataMapper::Query::Path
+ dump_custom_value(property_or_path.property, bind_value)
+ when Property
+ if property_or_path.custom?
+ property_or_path.type.dump(bind_value, property_or_path)
+ else
+ bind_value
+ end
+ else
+ bind_value
+ end
+ end
+
# TODO: check for other mutually exclusive operator + property
# combinations. For example if self's conditions were
# [ :gt, :amount, 5 ] and the other's condition is [ :lt, :amount, 2 ]
Please sign in to comment.
Something went wrong with that request. Please try again.