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

This commit is contained in:
Ernie Miller 2011-04-18 14:34:48 -04:00
parent cef7b8ecea
commit ee84a09337
5 changed files with 8 additions and 15 deletions

View File

@ -53,16 +53,8 @@ module Ransack
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 File

@ -51,9 +51,9 @@ module Ransack
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 File

@ -26,7 +26,7 @@ module Ransack
if ransacker
return ransacker.type
else
context.type_for(attr)
context.type_for(self)
end
end

View File

@ -7,6 +7,7 @@ module Ransack
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 File

@ -1,3 +1,3 @@
module Ransack
VERSION = "0.2.0"
VERSION = "0.2.1"
end