aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/scoping/named_scoping_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-03-27 19:31:34 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-03-27 19:56:01 +0900
commitb9be64cc3e2959c974c3036a0eb5a37fc8c7d580 (patch)
treed6c4bd21cf670cc632727e9041c55ff5e4efa088 /activerecord/test/cases/scoping/named_scoping_test.rb
parent1518457a67781f44276044e325aaaa97c9988741 (diff)
downloadrails-b9be64cc3e2959c974c3036a0eb5a37fc8c7d580.tar.gz
rails-b9be64cc3e2959c974c3036a0eb5a37fc8c7d580.tar.bz2
rails-b9be64cc3e2959c974c3036a0eb5a37fc8c7d580.zip
Bring back private class methods accessibility in named scope
The receiver in a scope was changed from `klass` to `relation` itself for all scopes (named scope, default_scope, and association scope) behaves consistently. In addition. Before 5.2, if both an AR model class and a Relation instance have same named methods (e.g. `arel_attribute`, `predicate_builder`, etc), named scope doesn't respect relation instance information. For example: ```ruby class Post < ActiveRecord::Base has_many :comments1, class_name: "RecentComment1" has_many :comments2, class_name: "RecentComment2" end class RecentComment1 < ActiveRecord::Base self.table_name = "comments" default_scope { where(arel_attribute(:created_at).gteq(2.weeks.ago)) } end class RecentComment2 < ActiveRecord::Base self.table_name = "comments" default_scope { recent_updated } scope :recent_updated, -> { where(arel_attribute(:updated_at).gteq(2.weeks.ago)) } end ``` If eager loading `Post.eager_load(:comments1, :comments2).to_a`, `:comments1` (default_scope) respects aliased table name, but `:comments2` (using named scope) may not work correctly since named scope doesn't respect relation instance information. See also 801ccab. But this is a breaking change between releases without deprecation. I decided to bring back private class methods accessibility in named scope. Fixes #31740. Fixes #32331.
Diffstat (limited to 'activerecord/test/cases/scoping/named_scoping_test.rb')
0 files changed, 0 insertions, 0 deletions