Skip to content

Conversation

@jrom
Copy link
Contributor

@jrom jrom commented Sep 27, 2011

Before this fix Model.except(something) wouldn't get rid of 'something'
clauses in the query. Same thing for Model.only().

The two deleted lines were introduced here to "evaluate default scopes at the last possible moment" and that made impossible to remove conditions from the default scope. The behavior after this fix is the same we had before Rails 3.1, which means #except and #only can modify the default_scope.

Before this fix Model.except(something) wouldn't get rid of 'something'
clauses in the query. Same thing for Model.only().
@jonleighton
Copy link
Member

Hmm, this is not really fixing it properly because it will simply mean that a relation after only or except won't have any default scope at all.

@jrom
Copy link
Contributor Author

jrom commented Sep 27, 2011

Oh shit, you're right. For some reason I had a test that checked that before and I ended up removing this code. I refactored my fix to the simplest solution but it turns out I screwed it so now it just loses the scope.

I can confirm it just loses the default scope:

>> User.count
   (0.5ms)  SELECT COUNT(*) FROM `users` WHERE ((`users`.`deleted` IS NULL OR `users`.`deleted` = 0))
=> 5
>> User.except(:order).count
   (0.4ms)  SELECT COUNT(*) FROM `users` 
=> 5

It turns out previous commit lost the scope after #except and #only
@jrom
Copy link
Contributor Author

jrom commented Sep 27, 2011

Added a failing test for this here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants