Permalink
Browse files

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

  • Loading branch information...
1 parent cef7b8e commit ee84a09337df2f2a3cdbb2d4f34fac40d5485bb1 @ernie ernie committed Apr 18, 2011
View
12 lib/ransack/adapters/active_record/3.0/context.rb
@@ -53,16 +53,8 @@ def klassify(obj)
end
def type_for(attr)
- return nil unless attr
- name = attr.name.to_s
- table = attr.relation.name
-
- unless @engine.connection.table_exists?(table)
- raise "No table named #{table} exists"
- end
-
- # TODO: optimize
- @engine.connection.columns(table).detect {|c| c.name == name}.type
+ return nil unless attr && attr.valid?
+ klassify(attr.parent).columns_hash[attr.arel_attribute.name.to_s].type
end
private
View
6 lib/ransack/adapters/active_record/context.rb
@@ -51,9 +51,9 @@ def klassify(obj)
end
def type_for(attr)
- return nil unless attr
- name = attr.name.to_s
- table = attr.relation.table_name
+ return nil unless attr && attr.valid?
+ name = attr.arel_attribute.name.to_s
+ table = attr.arel_attribute.relation.table_name
unless @engine.connection_pool.table_exists?(table)
raise "No table named #{table} exists"
View
2 lib/ransack/nodes/attribute.rb
@@ -26,7 +26,7 @@ def type
if ransacker
return ransacker.type
else
- context.type_for(attr)
+ context.type_for(self)
end
end
View
1 lib/ransack/nodes/bindable.rb
@@ -7,6 +7,7 @@ module Bindable
def attr
@attr ||= ransacker ? ransacker.attr_from(self) : context.table_for(parent)[attr_name]
end
+ alias :arel_attribute :attr
def ransacker
klass._ransackers[attr_name]
View
2 lib/ransack/version.rb
@@ -1,3 +1,3 @@
module Ransack
- VERSION = "0.2.0"
+ VERSION = "0.2.1"
end

0 comments on commit ee84a09

Please sign in to comment.