Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make sure we are using the adapter's column hash in AR 3.0

  • Loading branch information...
commit ee84a09337df2f2a3cdbb2d4f34fac40d5485bb1 1 parent cef7b8e
Ernie Miller authored April 18, 2011
12  lib/ransack/adapters/active_record/3.0/context.rb
@@ -53,16 +53,8 @@ def klassify(obj)
53 53
         end
54 54
 
55 55
         def type_for(attr)
56  
-          return nil unless attr
57  
-          name    = attr.name.to_s
58  
-          table   = attr.relation.name
59  
-
60  
-          unless @engine.connection.table_exists?(table)
61  
-            raise "No table named #{table} exists"
62  
-          end
63  
-
64  
-          # TODO: optimize
65  
-          @engine.connection.columns(table).detect {|c| c.name == name}.type
  56
+          return nil unless attr && attr.valid?
  57
+          klassify(attr.parent).columns_hash[attr.arel_attribute.name.to_s].type
66 58
         end
67 59
 
68 60
         private
6  lib/ransack/adapters/active_record/context.rb
@@ -51,9 +51,9 @@ def klassify(obj)
51 51
         end
52 52
 
53 53
         def type_for(attr)
54  
-          return nil unless attr
55  
-          name    = attr.name.to_s
56  
-          table   = attr.relation.table_name
  54
+          return nil unless attr && attr.valid?
  55
+          name    = attr.arel_attribute.name.to_s
  56
+          table   = attr.arel_attribute.relation.table_name
57 57
 
58 58
           unless @engine.connection_pool.table_exists?(table)
59 59
             raise "No table named #{table} exists"
2  lib/ransack/nodes/attribute.rb
@@ -26,7 +26,7 @@ def type
26 26
         if ransacker
27 27
           return ransacker.type
28 28
         else
29  
-          context.type_for(attr)
  29
+          context.type_for(self)
30 30
         end
31 31
       end
32 32
 
1  lib/ransack/nodes/bindable.rb
@@ -7,6 +7,7 @@ module Bindable
7 7
       def attr
8 8
         @attr ||= ransacker ? ransacker.attr_from(self) : context.table_for(parent)[attr_name]
9 9
       end
  10
+      alias :arel_attribute :attr
10 11
 
11 12
       def ransacker
12 13
         klass._ransackers[attr_name]
2  lib/ransack/version.rb
... ...
@@ -1,3 +1,3 @@
1 1
 module Ransack
2  
-  VERSION = "0.2.0"
  2
+  VERSION = "0.2.1"
3 3
 end

0 notes on commit ee84a09

Please sign in to comment.
Something went wrong with that request. Please try again.