Commit Graph

6 Commits

Author SHA1 Message Date
Jon Leighton
0a12a5f816 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
2012-03-21 22:18:18 +00:00
Jon Leighton
9a1a32ac2b Fix naughty trailing whitespace 2010-10-31 11:21:28 +00:00
Jon Leighton
915ea5ea82 Support the :primary_key option on a through reflection in a nested through association 2010-10-19 16:13:06 +01:00
Pratik Naik
d60bb0a9e4 Rename named_scope to scope 2010-01-18 04:38:19 +05:30
Matt Duncan
3b3798506b Adding :from scoping to ActiveRecord calculations
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1229 state:committed]
2009-08-09 12:43:07 +12:00
Matt Jones
d3fd997109 fix assignment to has_one :through associations.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
2008-11-15 18:20:39 +01:00