Permalink
Browse files

Write a more comprehensive CHANGELOG message [ci skip]

  • Loading branch information...
jonleighton committed Mar 8, 2013
1 parent f1082b8 commit 9f007d7fe5f90257c71baa2c4e7c76fb44512986
Showing with 45 additions and 3 deletions.
  1. +45 −3 activerecord/CHANGELOG.md
View
@@ -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'

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Mar 21, 2013

Member

Is not this line wrong?

@rafaelfranca

rafaelfranca Mar 21, 2013

Member

Is not this line wrong?

This comment has been minimized.

Show comment
Hide comment
@jonleighton

jonleighton Mar 22, 2013

Member

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

@jonleighton

jonleighton Mar 22, 2013

Member

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

+
+ ### 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

This comment has been minimized.

Show comment
Hide comment
@fxn

fxn Mar 8, 2013

Member

❤️

Member

fxn replied Mar 8, 2013

❤️

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Mar 8, 2013

Member

Awesome 💖

Awesome 💖

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Mar 8, 2013

Member

Daaaaamn. 😄

Member

steveklabnik replied Mar 8, 2013

Daaaaamn. 😄

Please sign in to comment.