Skip to content
Browse files

Write a more comprehensive CHANGELOG message [ci skip]

  • Loading branch information...
1 parent f1082b8 commit 9f007d7fe5f90257c71baa2c4e7c76fb44512986 @jonleighton jonleighton committed Mar 8, 2013
Showing with 45 additions and 3 deletions.
  1. +45 −3 activerecord/CHANGELOG.md
View
48 activerecord/CHANGELOG.md
@@ -1,8 +1,50 @@
## Rails 4.0.0 (unreleased) ##
-* Previously `Post.active.inactive` used to result in `Post.inactive`
- since the last where clause used to win while combining scopes.
- Now all the scopes will be merged using `AND`. Fixes #7365 .
+* Change the semantics of combining scopes to be the same as combining
+ class methods which return scopes. For example:
+
+ class User < ActiveRecord::Base
+ scope :active, -> { where state: 'active' }
+ scope :inactive, -> { where state: 'inactive' }
+ end
+
+ class Post < ActiveRecord::Base
+ def self.active
+ where state: 'active'
+ end
+
+ def self.inactive
+ where state: 'inactive'
+ end
+ end
+
+ ### BEFORE ###
+
+ User.where(state: 'active').where(state: 'inactive')
+ # => SELECT * FROM users WHERE state = 'active' AND state = 'inactive'
+
+ User.active.inactive
+ # => SELECT * FROM users WHERE state = 'inactive'
+
+ Post.active.inactive
+ # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
@rafaelfranca
Ruby on Rails member
rafaelfranca added a note Mar 21, 2013

Is not this line wrong?

@jonleighton
Ruby on Rails member
jonleighton added a note Mar 22, 2013

No, I don't think it's wrong. It's using Post, not User, which is using class methods rather than scopes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ ### AFTER ###
+
+ User.active.inactive
+ # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
+
+ Before this change, invoking a scope would merge it into the current
+ scope and return the result. `Relation#merge` applies "last where
+ wins" logic to de-duplicate the conditions, but this lead to
+ confusing and inconsistent behaviour. This fixes that.
+
+ If you really do want the "last where wins" logic, you can opt-in to
+ it like so:
+
+ User.active.merge(User.inactive)
+
+ Fixes #7365.
*Neeraj Singh* and *Jon Leighton*

3 comments on commit 9f007d7

@fxn
Ruby on Rails member
fxn commented on 9f007d7 Mar 8, 2013

:heart:

@carlosantoniodasilva
Ruby on Rails member

Awesome :sparkling_heart:

@steveklabnik
Ruby on Rails member

Daaaaamn. :smile:

Please sign in to comment.
Something went wrong with that request. Please try again.