Skip to content

Commit

Permalink
Write a more comprehensive CHANGELOG message [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Mar 8, 2013
1 parent f1082b8 commit 9f007d7
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions 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'

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Mar 21, 2013

Member

Is not this line wrong?

This comment has been minimized.

Copy link
@jonleighton

jonleighton Mar 22, 2013

Author 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*

Expand Down

3 comments on commit 9f007d7

@fxn
Copy link
Member

@fxn fxn commented on 9f007d7 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@carlosantoniodasilva
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 💖

@steveklabnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daaaaamn. 😄

Please sign in to comment.