diff options
author | Sammy Larbi <sam@codeodor.com> | 2014-08-31 14:18:02 -0500 |
---|---|---|
committer | Sammy Larbi <sam@codeodor.com> | 2014-09-04 10:05:01 -0500 |
commit | 4abbdbdf1656e9bed6f744723a901cbaf6878df4 (patch) | |
tree | e4cee59666ea912a081f80722d7218621b7ed8b9 /activerecord/test/models | |
parent | 40f9407b872add660db45e59316a5a195f16d563 (diff) | |
download | rails-4abbdbdf1656e9bed6f744723a901cbaf6878df4.tar.gz rails-4abbdbdf1656e9bed6f744723a901cbaf6878df4.tar.bz2 rails-4abbdbdf1656e9bed6f744723a901cbaf6878df4.zip |
Skip StatementCache for eager loaded associations (Fixes #16761)
Eagerly loaded collection and singular associations are ignored by the StatementCache, which causes errors when the queries they generate reference columns that were not eagerly loaded.
This commit skips the creation of the StatementCache as a fix for these scenarios.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/comment.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index 7a88299d08..b38b17e90e 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -52,3 +52,8 @@ class CommentThatAutomaticallyAltersPostBody < Comment comment.post.update_attributes(body: "Automatically altered") end end + +class CommentWithDefaultScopeReferencesAssociation < Comment + default_scope ->{ includes(:developer).order('developers.name').references(:developer) } + belongs_to :developer +end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 56a31011da..256b720c9a 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -218,3 +218,9 @@ class PostThatLoadsCommentsInAnAfterSaveHook < ActiveRecord::Base post.comments.load end end + +class PostWithCommentWithDefaultScopeReferencesAssociation < ActiveRecord::Base + self.table_name = 'posts' + has_many :comment_with_default_scope_references_associations, foreign_key: :post_id + has_one :first_comment, class_name: "CommentWithDefaultScopeReferencesAssociation", foreign_key: :post_id +end |