-
-
Save adam/209a199f3dc7d0b4709a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 162f7342437bbc0fa47a78d19a98da64915ec342 Mon Sep 17 00:00:00 2001 | |
From: Adam French <afrench@wieck.com> | |
Date: Sat, 16 Aug 2008 19:48:41 -0500 | |
Subject: [PATCH] late dumping of custom type values in query.rb | |
--- | |
lib/dm-core/query.rb | 34 +++++++++++++++++++--------------- | |
spec/integration/query_spec.rb | 6 ++++++ | |
2 files changed, 25 insertions(+), 15 deletions(-) | |
diff --git a/lib/dm-core/query.rb b/lib/dm-core/query.rb | |
index 9434dce..2514247 100644 | |
--- a/lib/dm-core/query.rb | |
+++ b/lib/dm-core/query.rb | |
@@ -189,8 +189,6 @@ module DataMapper | |
@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]) | |
@@ -217,18 +215,7 @@ module DataMapper | |
# deep-copy the condition tuples when copying the object | |
@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 | |
@@ -406,7 +393,7 @@ module DataMapper | |
def append_condition(clause, bind_value) | |
operator = :eql | |
bind_value = bind_value.call if bind_value.is_a?(Proc) | |
- | |
+ | |
property = case clause | |
when Property | |
clause | |
@@ -440,9 +427,26 @@ module DataMapper | |
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 ] | |
diff --git a/spec/integration/query_spec.rb b/spec/integration/query_spec.rb | |
index 731f081..8c0f23e 100644 | |
--- a/spec/integration/query_spec.rb | |
+++ b/spec/integration/query_spec.rb | |
@@ -439,6 +439,12 @@ if ADAPTER | |
vehicle.name.should == '10 ton delivery truck' | |
end | |
+ it "should accept 'lt', 'gt' modifiers on a DM::QueryPath" do | |
+ vehicles = QuerySpec::Vehicle.all( QuerySpec::Vehicle.factory.region.id.gt => 1) | |
+ end | |
+ | |
+ | |
+ | |
it 'should auto generate the link if a DM::Property from a different resource is in the :fields option' | |
it 'should create links with composite keys' | |
-- | |
1.5.6.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment