aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/table.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/table.rb')
-rw-r--r--lib/arel/table.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/arel/table.rb b/lib/arel/table.rb
index 2c7a2b7f93..b4b4a861b8 100644
--- a/lib/arel/table.rb
+++ b/lib/arel/table.rb
@@ -11,18 +11,19 @@ module Arel
# TableAlias and Table both have a #table_name which is the name of the underlying table
alias :table_name :name
- def initialize name, options = {}
+ def initialize(name, as: nil, type_caster: nil)
@name = name.to_s
@columns = nil
@aliases = []
+ @type_caster = type_caster
# Sometime AR sends an :as parameter to table, to let the table know
# that it is an Alias. We may want to override new, and return a
# TableAlias node?
- @table_alias = options[:as]
- if @table_alias.to_s == @name
- @table_alias = nil
+ if as.to_s == @name
+ as = nil
end
+ @table_alias = as
end
def alias name = "#{self.name}_2"
@@ -98,6 +99,18 @@ module Arel
end
alias :== :eql?
+ def type_cast_for_database(attribute_name, value)
+ type_caster.type_cast_for_database(attribute_name, value)
+ end
+
+ def able_to_type_cast?
+ !type_caster.nil?
+ end
+
+ protected
+
+ attr_reader :type_caster
+
private
def attributes_for columns