aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-05-10 13:46:37 +0200
committerYves Senn <yves.senn@gmail.com>2014-05-10 13:51:31 +0200
commited56e596a0467390011bc9d56d462539776adac1 (patch)
tree15a1746ac7c4d2a421085618b64e4d5c343ea154 /activerecord/lib/active_record/reflection.rb
parentf55f5e2b6d265764ff8ac23d56f768fda881f88f (diff)
downloadrails-ed56e596a0467390011bc9d56d462539776adac1.tar.gz
rails-ed56e596a0467390011bc9d56d462539776adac1.tar.bz2
rails-ed56e596a0467390011bc9d56d462539776adac1.zip
deprecate, join, preload, eager load of instance dependent associations.
Closes #15024. These operations happen before instances are created. The current behavior is misleading and can result in broken behavior.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 7f4d77849a..0eec6774a0 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -278,6 +278,20 @@ module ActiveRecord
end
end
+ def check_preloadable!
+ return unless scope
+
+ if scope.arity > 0
+ ActiveSupport::Deprecation.warn <<-WARNING
+The association scope '#{name}' is instance dependent (the scope block takes an argument).
+Preloading happens before the individual instances are created. This means that there is no instance
+being passed to the association scope. This will most likely result in broken or incorrect behavior.
+Joining, Preloading and eager loading of these associations is deprecated and will be removed in the future.
+ WARNING
+ end
+ end
+ alias :check_eager_loadable! :check_preloadable!
+
def join_id_for(owner) #:nodoc:
key = (source_macro == :belongs_to) ? foreign_key : active_record_primary_key
owner[key]