aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-02 14:52:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-02 14:52:59 -0700
commit75beb6c7c3173ba78f212cfeccaa172beccf4e92 (patch)
treec1dcf5786ebdc9d466753d7745b1ab167b664464 /activerecord/lib/active_record/associations
parent5d8b7760ee3700c6d897e51e01dd2055da80506b (diff)
downloadrails-75beb6c7c3173ba78f212cfeccaa172beccf4e92.tar.gz
rails-75beb6c7c3173ba78f212cfeccaa172beccf4e92.tar.bz2
rails-75beb6c7c3173ba78f212cfeccaa172beccf4e92.zip
push constructable? on to the reflection
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb4
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb8
-rw-r--r--activerecord/lib/active_record/associations/builder/has_one.rb4
-rw-r--r--activerecord/lib/active_record/associations/builder/singular_association.rb8
4 files changed, 6 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index 1059fc032d..b8a856f001 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -31,7 +31,7 @@ module ActiveRecord::Associations::Builder
builder = new(name, scope, options, &block)
reflection = builder.build(model)
- builder.define_accessors model
+ builder.define_accessors model, reflection
builder.define_callbacks model, reflection
builder.define_extensions model
reflection
@@ -82,7 +82,7 @@ module ActiveRecord::Associations::Builder
#
# Post.first.comments and Post.first.comments= methods are defined by this method...
- def define_accessors(model)
+ def define_accessors(model, reflection)
mixin = model.generated_feature_methods
define_readers(mixin)
define_writers(mixin)
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 51d963e18d..a2f4758b57 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -8,10 +8,6 @@ module ActiveRecord::Associations::Builder
super + [:foreign_type, :polymorphic, :touch]
end
- def constructable?
- !options[:polymorphic]
- end
-
def valid_dependent_options
[:destroy, :delete]
end
@@ -22,7 +18,7 @@ module ActiveRecord::Associations::Builder
add_touch_callbacks(model, reflection) if options[:touch]
end
- def define_accessors(mixin)
+ def define_accessors(mixin, reflection)
super
add_counter_cache_methods mixin
end
@@ -58,7 +54,7 @@ module ActiveRecord::Associations::Builder
if (@_after_create_counter_called ||= false)
@_after_create_counter_called = false
- elsif attribute_changed?(foreign_key) && !new_record? && association.constructable?
+ elsif attribute_changed?(foreign_key) && !new_record? && reflection.constructable?
model = reflection.klass
foreign_key_was = attribute_was foreign_key
foreign_key = attribute foreign_key
diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb
index 62d454ce55..accd29e5ef 100644
--- a/activerecord/lib/active_record/associations/builder/has_one.rb
+++ b/activerecord/lib/active_record/associations/builder/has_one.rb
@@ -10,10 +10,6 @@ module ActiveRecord::Associations::Builder
valid
end
- def constructable?
- !options[:through]
- end
-
def valid_dependent_options
[:destroy, :delete, :nullify, :restrict_with_error, :restrict_with_exception]
end
diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb
index d97c0e9afd..10d568ebc0 100644
--- a/activerecord/lib/active_record/associations/builder/singular_association.rb
+++ b/activerecord/lib/active_record/associations/builder/singular_association.rb
@@ -6,13 +6,9 @@ module ActiveRecord::Associations::Builder
super + [:remote, :dependent, :counter_cache, :primary_key, :inverse_of]
end
- def constructable?
- true
- end
-
- def define_accessors(model)
+ def define_accessors(model, reflection)
super
- define_constructors(model.generated_feature_methods) if constructable?
+ define_constructors(model.generated_feature_methods) if reflection.constructable?
end
# Defines the (build|create)_association methods for belongs_to or has_one association