aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-06-13 16:03:40 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-06-13 16:03:40 -0700
commitf4767bc8448d3d606149618cb279234dfcf803e7 (patch)
tree2e89d5d7fdd322196218dc0da8675c8377b600d9 /activerecord/lib/active_record/reflection.rb
parentbf966ad8eef6e42c0d23b48cd1ccc04809d7f68f (diff)
downloadrails-f4767bc8448d3d606149618cb279234dfcf803e7.tar.gz
rails-f4767bc8448d3d606149618cb279234dfcf803e7.tar.bz2
rails-f4767bc8448d3d606149618cb279234dfcf803e7.zip
calculate types on construction
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb12
1 files changed, 4 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 246f0761b3..82d728e2e9 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -189,10 +189,14 @@ module ActiveRecord
@klass ||= active_record.send(:compute_type, class_name)
end
+ attr_reader :type, :foreign_type
+
def initialize(*args)
super
@collection = [:has_many, :has_and_belongs_to_many].include?(macro)
@automatic_inverse_of = nil
+ @type = options[:as] && "#{options[:as]}_type"
+ @foreign_type = options[:foreign_type] || "#{name}_type"
end
# Returns a new, unsaved instance of the associated class. +attributes+ will
@@ -217,14 +221,6 @@ module ActiveRecord
@foreign_key ||= options[:foreign_key] || derive_foreign_key
end
- def foreign_type
- @foreign_type ||= options[:foreign_type] || "#{name}_type"
- end
-
- def type
- @type ||= options[:as] && "#{options[:as]}_type"
- end
-
def primary_key_column
klass.columns_hash[klass.primary_key]
end