ar-extensions 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/lib/ar-extensions/finders.rb +11 -17
- data/lib/ar-extensions/version.rb +1 -1
- metadata +1 -1
data/ChangeLog
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
2009-07-22 zdennis <zach.dennis@gmail.com>
|
2
|
+
|
3
|
+
* Forgot to push past commit of fixing #sanitize_sql method signatures to supported passing in a table_name. This satisfies the change to the ActiveRecord API in Rails commit 489abfd3b23f3c4b3de86aeb3bde3970771c001b on April 20th.
|
4
|
+
|
1
5
|
2009-04-17 blythedunham <blythedunham@gmail.com>
|
2
6
|
|
3
7
|
* Added MySQL support for save, create, replace options - :ignore, :on_duplicate_key_update, :keywords, :reload, :keywords, :pre_sql, :post_sql
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'active_record/version'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
3
|
module ActiveRecord::ConnectionAdapters::Quoting
|
7
|
-
|
8
4
|
alias :quote_before_arext :quote
|
9
5
|
def quote( value, column=nil ) # :nodoc:
|
10
6
|
if value.is_a?( Regexp )
|
@@ -23,26 +19,26 @@ class ActiveRecord::Base
|
|
23
19
|
private
|
24
20
|
|
25
21
|
alias :sanitize_sql_orig :sanitize_sql
|
26
|
-
def sanitize_sql(
|
22
|
+
def sanitize_sql(arg, table_name = quoted_table_name) # :nodoc:
|
27
23
|
return if arg.blank? # don't process arguments like [], {}, "" or nil
|
28
24
|
if arg.respond_to?( :to_sql )
|
29
|
-
arg = sanitize_sql_by_way_of_duck_typing(
|
30
|
-
elsif arg.is_a?(
|
31
|
-
arg = sanitize_sql_from_hash(
|
25
|
+
arg = sanitize_sql_by_way_of_duck_typing(arg)
|
26
|
+
elsif arg.is_a?(Hash)
|
27
|
+
arg = sanitize_sql_from_hash(arg, table_name)
|
32
28
|
elsif arg.is_a?( Array ) and arg.size == 2 and arg.first.is_a?( String ) and arg.last.is_a?( Hash )
|
33
|
-
arg = sanitize_sql_from_string_and_hash(
|
29
|
+
arg = sanitize_sql_from_string_and_hash(arg, table_name)
|
34
30
|
end
|
35
|
-
sanitize_sql_orig(
|
31
|
+
sanitize_sql_orig(arg)
|
36
32
|
end
|
37
33
|
|
38
|
-
def sanitize_sql_by_way_of_duck_typing(
|
34
|
+
def sanitize_sql_by_way_of_duck_typing(arg) #: nodoc:
|
39
35
|
arg.to_sql( caller )
|
40
36
|
end
|
41
37
|
|
42
|
-
def sanitize_sql_from_string_and_hash(
|
38
|
+
def sanitize_sql_from_string_and_hash(arr, table_name = quoted_table_name) # :nodoc:
|
43
39
|
return arr if arr.first =~ /\:[\w]+/
|
44
40
|
return arr if arr.last.empty? # skip empty hash conditions, ie: :conditions => ["", {}]
|
45
|
-
arr2 = sanitize_sql_from_hash( arr.last )
|
41
|
+
arr2 = sanitize_sql_from_hash( arr.last, table_name )
|
46
42
|
if arr2.empty?
|
47
43
|
conditions = arr.first
|
48
44
|
else
|
@@ -52,7 +48,7 @@ class ActiveRecord::Base
|
|
52
48
|
conditions
|
53
49
|
end
|
54
50
|
|
55
|
-
def sanitize_sql_from_hash(
|
51
|
+
def sanitize_sql_from_hash(hsh, table_name = quoted_table_name) #:nodoc:
|
56
52
|
conditions, values = [], []
|
57
53
|
hsh = expand_hash_conditions_for_aggregates(hsh) # introduced in Rails 2.0.2
|
58
54
|
|
@@ -61,7 +57,7 @@ class ActiveRecord::Base
|
|
61
57
|
conditions << sanitize_sql_by_way_of_duck_typing( val )
|
62
58
|
next
|
63
59
|
elsif val.is_a?(Hash) # don't mess with ActiveRecord hash nested hash functionality
|
64
|
-
conditions << sanitize_sql_hash_for_conditions(key => val)
|
60
|
+
conditions << sanitize_sql_hash_for_conditions({key => val}, table_name)
|
65
61
|
else
|
66
62
|
sql = nil
|
67
63
|
result = ActiveRecord::Extensions.process( key, val, self )
|
@@ -74,8 +70,6 @@ class ActiveRecord::Base
|
|
74
70
|
if attr.include?('.')
|
75
71
|
table_name, attr = attr.split('.', 2)
|
76
72
|
table_name = connection.quote_table_name(table_name)
|
77
|
-
else
|
78
|
-
table_name = quoted_table_name
|
79
73
|
end
|
80
74
|
# ActiveRecord in 2.3.1 changed the method signature for
|
81
75
|
# the method attribute_condition
|