diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-06-13 16:03:40 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-06-13 16:03:40 -0700 |
commit | f4767bc8448d3d606149618cb279234dfcf803e7 (patch) | |
tree | 2e89d5d7fdd322196218dc0da8675c8377b600d9 /activerecord/lib/active_record | |
parent | bf966ad8eef6e42c0d23b48cd1ccc04809d7f68f (diff) | |
download | rails-f4767bc8448d3d606149618cb279234dfcf803e7.tar.gz rails-f4767bc8448d3d606149618cb279234dfcf803e7.tar.bz2 rails-f4767bc8448d3d606149618cb279234dfcf803e7.zip |
calculate types on construction
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 12 |
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 |