Skip to content
This repository
Browse code

Changelog and doc updates for the previous changes.

  • Loading branch information...
commit 3205c768b7c592e5b96fdf6a6dd0fd3c2c9e5775 1 parent d109954
Jon Leighton jonleighton authored
24 activerecord/CHANGELOG.md
Source Rendered
... ... @@ -1,5 +1,24 @@
1 1 ## Rails 4.0.0 (unreleased) ##
2 2
  3 +* `Model.all` now returns an `ActiveRecord::Relation`, rather than an
  4 + array of records. Use `Model.to_a` or `Relation#to_a` if you really
  5 + want an array.
  6 +
  7 + In some specific cases, this may cause breakage when upgrading.
  8 + However in most cases the `ActiveRecord::Relation` will just act as a
  9 + lazy-loaded array and there will be no problems.
  10 +
  11 + Note that calling `Model.all` with options (e.g.
  12 + `Model.all(conditions: '...')` was already deprecated, but it will
  13 + still return an array in order to make the transition easier.
  14 +
  15 + `Model.scoped` is deprecated in favour of `Model.all`.
  16 +
  17 + `Relation#all` still returns an array, but is deprecated (since it
  18 + would serve no purpose if we made it return a `Relation`).
  19 +
  20 + *Jon Leighton*
  21 +
3 22 * Deprecate `update_column` method in favor of `update_columns`.
4 23
5 24 *Rafael Mendonça França*
@@ -249,13 +268,12 @@
249 268
250 269 Note that as an interim step, it is possible to rewrite the above as:
251 270
252   - Post.scoped(:where => { :comments_count => 10 }, :limit => 5)
  271 + Post.all.merge(:where => { :comments_count => 10 }, :limit => 5)
253 272
254 273 This could save you a lot of work if there is a lot of old-style
255 274 finder usage in your application.
256 275
257   - Calling `Post.scoped(options)` is a shortcut for
258   - `Post.scoped.merge(options)`. `Relation#merge` now accepts a hash of
  276 + `Relation#merge` now accepts a hash of
259 277 options, but they must be identical to the names of the equivalent
260 278 finder method. These are mostly identical to the old-style finder
261 279 option names, except in the following cases:
12 activerecord/lib/active_record/relation/query_methods.rb
@@ -129,7 +129,7 @@ def references!(*args)
129 129 #
130 130 # First: takes a block so it can be used just like Array#select.
131 131 #
132   - # Model.scoped.select { |m| m.field == value }
  132 + # Model.all.select { |m| m.field == value }
133 133 #
134 134 # This will build an array of objects from the database for the scope,
135 135 # converting them into an array and iterating through them using Array#select.
@@ -503,7 +503,7 @@ def create_with(value)
503 503 # Like #create_with but modifies the relation in place. Raises
504 504 # +ImmutableRelation+ if the relation has already been loaded.
505 505 #
506   - # users = User.scoped.create_with!(name: 'Oscar')
  506 + # users = User.all.create_with!(name: 'Oscar')
507 507 # users.new.name # => 'Oscar'
508 508 def create_with!(value)
509 509 self.create_with_value = value ? create_with_value.merge(value) : {}
@@ -566,16 +566,16 @@ def uniq!(value = true)
566 566 # end
567 567 # end
568 568 #
569   - # scope = Model.scoped.extending(Pagination)
  569 + # scope = Model.all.extending(Pagination)
570 570 # scope.page(params[:page])
571 571 #
572 572 # You can also pass a list of modules:
573 573 #
574   - # scope = Model.scoped.extending(Pagination, SomethingElse)
  574 + # scope = Model.all.extending(Pagination, SomethingElse)
575 575 #
576 576 # === Using a block
577 577 #
578   - # scope = Model.scoped.extending do
  578 + # scope = Model.all.extending do
579 579 # def page(number)
580 580 # # pagination code goes here
581 581 # end
@@ -584,7 +584,7 @@ def uniq!(value = true)
584 584 #
585 585 # You can also use a block and a module list:
586 586 #
587   - # scope = Model.scoped.extending(Pagination) do
  587 + # scope = Model.all.extending(Pagination) do
588 588 # def per_page(number)
589 589 # # pagination code goes here
590 590 # end
15 guides/source/active_record_querying.textile
Source Rendered
@@ -1132,21 +1132,6 @@ Using a class method is the preferred way to accept arguments for scopes. These
1132 1132 category.posts.created_before(time)
1133 1133 </ruby>
1134 1134
1135   -h4. Working with scopes
1136   -
1137   -Where a relational object is required, the +scoped+ method may come in handy. This will return an +ActiveRecord::Relation+ object which can have further scoping applied to it afterwards. A place where this may come in handy is on associations
1138   -
1139   -<ruby>
1140   -client = Client.find_by_first_name("Ryan")
1141   -orders = client.orders.scoped
1142   -</ruby>
1143   -
1144   -With this new +orders+ object, we are able to ascertain that this object can have more scopes applied to it. For instance, if we wanted to return orders only in the last 30 days at a later point.
1145   -
1146   -<ruby>
1147   -orders.where("created_at > ?", 30.days.ago)
1148   -</ruby>
1149   -
1150 1135 h4. Applying a default scope
1151 1136
1152 1137 If we wish for a scope to be applied across all queries to the model we can use the +default_scope+ method within the model itself.

0 comments on commit 3205c76

Please sign in to comment.
Something went wrong with that request. Please try again.