1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

26 commits

Author SHA1 Message Date
Francesco Rodriguez
6dec7535fd update AR::Scoping documentation [ci skip] 2012-09-21 23:25:52 -05:00
Xavier Noria
077372b20d load active_support/deprecation in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
5e1b92044c load active_support/core_ext/class/attribute in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
64bc8447c2 load active_support/concern in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
8f58d6e507 load active_support/core_ext/object/blank in active_support/rails 2012-08-02 21:59:22 +02:00
Jon Leighton
b658cf1198 Deprecate ActiveRecord::Base.scoped.
It doesn't serve much purpose now that ActiveRecord::Base.all returns a
Relation.

The code is moved to active_record_deprecated_finders.
2012-07-27 17:27:47 +01:00
Jon Leighton
6a81ccd69d ActiveRecord::Base.all returns a Relation.
Previously it returned an Array.

If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This
is more explicit.

In most cases this should not break existing code, since
Relations use method_missing to delegate unknown methods to #to_a
anyway.
2012-07-27 13:34:12 +01:00
Francesco Rodriguez
62463d11b8 remove :nodoc: of AR::Scoping#unscoped [ci skip] 2012-07-01 15:53:27 -05:00
Jon Leighton
e030f26ad3 Simplify AR configuration code.
Get rid of ActiveModel::Configuration, make better use of
ActiveSupport::Concern + class_attribute, etc.
2012-06-15 19:15:36 +01:00
Jon Leighton
af27c8b041 extract deprecated code 2012-04-25 15:45:06 +01:00
Jon Leighton
618c5fc3c0 Extract deprecated code 2012-04-25 15:45:06 +01:00
Jon Leighton
f3fce59d13 extract to active_record_deprecated_finders 2012-04-25 15:45:05 +01:00
Jon Leighton
408437334b giving a hash to default scope should not be deprecated (well, not for this reason) 2012-04-25 15:45:05 +01:00
dcurtis
248fa70ccd Corrected grammatical errors in schema_dumper and scoping/default 2012-04-10 22:05:43 -07:00
Benedikt Deicke
68677ffb82 Removes caching from ActiveRecord::Core::ClassMethods#relation
The #relation method gets called in four places and the return value was instantly cloned in three of them. The only place that did not clone was ActiveRecord::Scoping::Default::ClassMethods#unscoped. This introduced a bug described in #5667 and should really clone the relation, too. This means all four places would clone the relation, so it doesn't make a lot of sense caching it in the first place.

The four places with calls to relations are:

activerecord/lib/active_record/scoping/default.rb:110:in `block in build_default_scope'"
activerecord/lib/active_record/scoping/default.rb:42:in `unscoped'"
activerecord/lib/active_record/scoping/named.rb:38:in `scoped'"
activerecord/lib/active_record/scoping/named.rb:52:in `scope_attributes'"
2012-04-03 17:00:37 +02:00
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
fd68bd23b6 Avoid obscure &Proc.new thing 2012-03-21 20:37:22 +00:00
Jon Leighton
f6db31ec16 Remove valid_scope_name? check - use ruby
scope is syntactic sugar for defining a class method. Ruby allows
redefining methods but emits a warning when run with -w. So let's
not implement our own logic for this. Users should run with -w if they
want to be warned about redefined methods.
2012-03-21 20:30:48 +00:00
Jon Leighton
884e5b7558 no need for cast 2012-03-21 20:25:51 +00:00
Jon Leighton
7c1275a005 no need for lvar 2012-03-21 20:23:46 +00:00
Xavier Noria
e99987bc30 app code in general wants Time.current, not Time.now 2011-12-28 23:47:10 +01:00
Jon Leighton
93c1f11c0a Support configuration on ActiveRecord::Model.
The problem: We need to be able to specify configuration in a way that
can be inherited to models that include ActiveRecord::Model. So it is
no longer sufficient to put 'top level' config on ActiveRecord::Base,
but we do want configuration specified on ActiveRecord::Base and
descendants to continue to work.

So we need something like class_attribute that can be defined on a
module but that is inherited when ActiveRecord::Model is included.

The solution: added ActiveModel::Configuration module which provides a
config_attribute macro. It's a bit specific hence I am not putting this
in Active Support or making it a 'public API' at present.
2011-12-28 18:27:41 +00:00
Vijay Dev
500ca98fef Merge branch 'master' of github.com:lifo/docrails 2011-12-20 22:18:42 +05:30
Hendy Tanata
5fe5effe32 Improve doc for ActiveRecord::Base.unscoped. 2011-12-18 01:10:02 -08:00
Sergey Nartimov
04cea56d89 call scope within unscoped to prevent duplication of where values 2011-12-17 14:41:17 +03:00
Jon Leighton
2b22564c4e Move DefaultScope and NamedScope under Scoping 2011-12-15 20:45:42 +00:00