aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-03-21 22:18:18 +0000
committerJon Leighton <j@jonathanleighton.com>2012-03-21 22:18:18 +0000
commit0a12a5f8169685915cbb7bf4d0a7bb482f7f2fd2 (patch)
tree77ac1032a9ff780fbf3ac92549b0a9de84fbdcba /activerecord/CHANGELOG.md
parentfd68bd23b602ef2a7b038b66e787604df9192c6d (diff)
downloadrails-0a12a5f8169685915cbb7bf4d0a7bb482f7f2fd2.tar.gz
rails-0a12a5f8169685915cbb7bf4d0a7bb482f7f2fd2.tar.bz2
rails-0a12a5f8169685915cbb7bf4d0a7bb482f7f2fd2.zip
Deprecate eager-evaluated scopes.
Don't use this: scope :red, where(color: 'red') default_scope where(color: 'red') Use this: scope :red, -> { where(color: 'red') } default_scope { where(color: 'red') } The former has numerous issues. It is a common newbie gotcha to do the following: scope :recent, where(published_at: Time.now - 2.weeks) Or a more subtle variant: scope :recent, -> { where(published_at: Time.now - 2.weeks) } scope :recent_red, recent.where(color: 'red') Eager scopes are also very complex to implement within Active Record, and there are still bugs. For example, the following does not do what you expect: scope :remove_conditions, except(:where) where(...).remove_conditions # => still has conditions
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r--activerecord/CHANGELOG.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 5a289a5aac..46031e7c13 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,36 @@
## Rails 4.0.0 (unreleased) ##
+* Deprecate eager-evaluated scopes.
+
+ Don't use this:
+
+ scope :red, where(color: 'red')
+ default_scope where(color: 'red')
+
+ Use this:
+
+ scope :red, -> { where(color: 'red') }
+ default_scope { where(color: 'red') }
+
+ The former has numerous issues. It is a common newbie gotcha to do
+ the following:
+
+ scope :recent, where(published_at: Time.now - 2.weeks)
+
+ Or a more subtle variant:
+
+ scope :recent, -> { where(published_at: Time.now - 2.weeks) }
+ scope :recent_red, recent.where(color: 'red')
+
+ Eager scopes are also very complex to implement within Active
+ Record, and there are still bugs. For example, the following does
+ not do what you expect:
+
+ scope :remove_conditions, except(:where)
+ where(...).remove_conditions # => still has conditions
+
+ *Jon Leighton*
+
* Remove IdentityMap
IdentityMap has never graduated to be an "enabled-by-default" feature, due