aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_proxy.rb
Commit message (Collapse)AuthorAgeFilesLines
* Remove association(true) references from docs [ci skip]Eugene Kenny2017-10-161-4/+0
| | | | | Passing `true` to force an association to reload its records from the database was deprecated in 5.0 and removed in 5.1.
* Delegate to `Enumerable#find` for `CollectionProxy`Ryuta Kamizono2017-08-131-2/+3
| | | | | Since `Relation` includes `Enumerable`, it is enough to use `super` simply.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Move clearing of @offsets cache to reset_scopeJohn Hawthorn2017-06-211-2/+1
|
* Clear offset cache on CollectionProxy reset/reloadJohn Hawthorn2017-06-201-0/+2
| | | | | | | | | | | | | | The `@offsets` cache is used by FinderMethods to cache records found by find_nth. This cache is cleared in AR::Relation#reset, but not in CollectionProxy#reset or CollectionProxy#reload. Because of this, since #29098, calling #first/#find_nth/etc after calling #reload or #reset on an association could return a stale record. This is an issue both when the full association target is loaded and when the item is loaded in #find_nth. This commit solves the problem by clearing the `@offsets` cache in CollectionProxy#reset and CollectionProxy#reload.
* Cache the association proxy objectRyuta Kamizono2017-05-281-3/+6
| | | | | | | | | | Some third party modules expects that association returns same proxy object each time (e.g. for stubbing collection methods: https://github.com/rspec/rspec-rails/issues/1817). So I decided that cache the proxy object and reset scope in the proxy object each time. Related context: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
* Fix association with extension issuesRyuta Kamizono2017-05-281-21/+3
| | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`Ryuta Kamizono2017-04-221-10/+18
| | | | | | | | | | `ClassSpecificRelation` has `method_missing` and the `method_missing` is called first. if an associated class has the missing method in a relation, never reach to the `method_missing` in the `CollectionProxy`. I extracted `DelegateExtending` and included it to the delegate class that including `ClassSpecificRelation` to fix the issue. Fixes https://github.com/rails/rails/pull/28246#issuecomment-296033784.
* Remove `CollectionProxy#uniq`Ryuta Kamizono2017-03-231-4/+0
| | | | | Since #28473 `uniq` is delegated to `records`, so `CollectionProxy#uniq` is unnecessary.
* Fix extension method with dirty target in has_many associationsRyuta Kamizono2017-03-201-2/+3
| | | | | | | Extension methods should not delegate to `scope` to respect dirty target on `CollectionProxy`. Fixes #28419.
* Fix select with block doesn't return newly built records in has_many associationRyuta Kamizono2017-03-091-2/+2
| | | | | | | | The `select` in `QueryMethods` is also an enumerable method. Enumerable methods with block should delegate to `records` on `CollectionProxy`, not `scope`. Fixes #28348.
* Revert "Dupping a CollectionProxy should dup the load_target"eileencodes2017-02-281-4/+0
| | | | | | | | | I incorrectly changed behavior of `dup`. Reading the original issue I thought that `dup` should retain the original contents of the record and it's associations but it is in fact supposed to be a copy as if a record had been reinitialized. This reverts commit ca8c21df0fdbf1f03ba2f7fb16b39c3282dc1be0.
* Dupping a CollectionProxy should dup the load_targeteileencodes2017-02-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Rails 3.2 dupping a `CollectionProxy` would dup it's `load_target` as well. That functionality has been broken since the release of Rails 4.0. I hit this in an application upgrade and wondered why duplicating a CollectionProxy and assigning it to a variable stopped working. When calling `dup` on a `CollectionProxy` only the owner (ex. topic) was getting duplicated and the `load_target` would remain in tact with it's original object ID. Dupping the `load_target` is useful for performing a logging operation after records have been destroyed in a method. For example: ``` def transfer_operation saved_replies = topic.replies topic.replies.clear saved_replies.each do |reply| user.update_replies_count! end end ``` This change adds a `initialize_dup` method that performs a `deep_dup` on the `@associatiation` so that the `load_target` is dupped as well. Fixes #17117
* Merge pull request #25877 from kamipo/delegate_to_scope_rather_than_mergeMatthew Draper2017-02-211-13/+24
|\ | | | | Delegate to `scope` rather than `merge!` for collection proxy
| * Define `respond_to_missing?` instead of `respond_to?`Ryuta Kamizono2017-02-211-4/+4
| |
| * Cache target scope for collection proxyRyuta Kamizono2016-12-251-2/+3
| |
| * Delegate to `scope` rather than `merge!` for collection proxyRyuta Kamizono2016-12-251-11/+21
| | | | | | | | | | `merge! association.scope(nullify: false)` is expensive but most methods do not need the merge.
* | Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-2/+2
|/ | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-5/+3
|
* Respect new records for `CollectionProxy#uniq`Ryuta Kamizono2016-11-131-3/+16
| | | | | | | | | | | | | Currently if `CollectionProxy` has more than one new record, `CollectionProxy#uniq` result is incorrect. And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db. But the `uniq` method and the `SELECT DISTINCT` method are different methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT` method, not for the `uniq` method. Therefore, reverting the alias in `CollectionProxy` to fix the inconsistency and to have the both methods.
* Fix regression caused due to removal of select method from CollectionAssociationPrathamesh Sonpatki2016-10-221-6/+0
| | | | | | | | | | | | | | | | - CollectionAssociation#select was removed in https://github.com/rails/rails/pull/25989 in favor of QueryMethods#select but it caused a regression when passing arguments to select and a block. - This used to work earlier in Rails 4.2 and Rails 5. See gist https://gist.github.com/prathamesh-sonpatki/a7df922273473a77dfbc742a4be4b618. - This commit restores the behavior of Rails 4.2 and Rails 5.0.0 to allow passing arguments and block at the same time but also deprecates it. - Because, these arguments do not have any effect on the output of select when select is used with a block. - Updated documentation to remove the example passing arguments and block at the same time to `CollectionProxy#select`.
* Revert " [ci skip] Remove duplicate example."Vipul A M2016-09-061-0/+5
|
* [ci skip] Remove duplicate example.Aditya Kapoor2016-09-061-5/+0
|
* Remove unnecessary `count` method for collection proxyRyuta Kamizono2016-09-041-11/+14
| | | | Simply use its own method because `CollectionProxy` inherits `Relation`.
* Remove unnecessary `any?` and `many?` methods for collection proxyRyuta Kamizono2016-08-191-6/+12
| | | | Simply use its own methods because `CollectionProxy` inherits `Relation`.
* Remove unnecessary `length` method for collection proxyRyuta Kamizono2016-08-191-3/+6
| | | | | | | `length` is delegated to `records` (`load_target`) by `ActiveRecord::Delegation`. https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/relation/delegation.rb#L38
* Merge pull request #25989 from ↵Rafael França2016-08-191-3/+6
|\ | | | | | | | | kamipo/remove_unnecessary_select_for_collection_proxy Remove unnecessary `select` method for `CollectionProxy`
| * Remove unnecessary `select` method for `CollectionProxy`Ryuta Kamizono2016-08-181-3/+6
| | | | | | | | | | | | | | Currently `CollectionProxy` inherits `Relation` and `Relation` includes `QueryMethods`. This method is completely duplicated. https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/relation/query_methods.rb#L271-L275
* | Remove unnecessary ordinal methods for collection associationRyuta Kamizono2016-08-181-26/+68
|/ | | | | Currently `CollectionProxy` inherits `Relation` therefore we can use its own methods rather than delegating to collection association.
* Merge pull request #25976 from kamipo/pluck_uses_loaded_targetRafael França2016-08-171-1/+12
|\ | | | | `pluck` should use `records` (`load_target`) when `loaded?` is true
| * `pluck` should use `records` (`load_target`) when `loaded?` is trueRyuta Kamizono2016-08-041-1/+12
| |
* | Fix inconsistent the signature of finder methods for collection associationRyuta Kamizono2016-08-161-18/+18
| | | | | | | | | | | | | | `#second`, `#third`, etc finder methods was added in 03855e790de2224519f55382e3c32118be31eeff. But the signature of these methods is inconsistent with the original finder methods. And also the signature of `#first` and `#last` methods is different from the original. This commit fixes the inconsistency.
* | `CollectionProxy#take` should respect dirty targetRyuta Kamizono2016-08-141-2/+2
|/ | | | | `#first`, `#second`, ..., `#last` methods respects dirty target. But `#take` doesn't respect it. This commit fixes the inconsistent behavior.
* Merge pull request #25941 from kamipo/finder_methods_uses_load_targetRafael França2016-07-281-1/+1
|\ | | | | `FinderMethods` uses `records` (`load_target`) when `loaded?` is true
| * `FinderMethods` uses `records` (`load_target`) when `loaded?` is trueRyuta Kamizono2016-07-281-1/+1
| |
* | Fix to `CollectionProxy#load` does `load_target`Ryuta Kamizono2016-07-251-0/+6
|/
* Add `exists?` and `update_all` to `CollectionProxy` for respects an ↵Ryuta Kamizono2016-07-201-5/+1
| | | | | | association scope Fixes #25732.
* [ci skip] fix a typoYamaguchi.Tomoki2016-07-151-1/+1
|
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-2/+2
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Forward ActiveRecord::Relation#count to Enumerable#count if block givenErik Michaels-Ober2016-03-191-3/+9
|
* Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-211-0/+4
| | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-101-4/+4
|
* allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-091-0/+10
|
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-9/+9
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* fix broken RDoc markup. Use `<tt>` instead of `+`. [ci skip]Yves Senn2015-10-141-3/+3
|
* Fix `ActiveRecord::RecordNotFound` error message with custom primary key [ci ↵amitkumarsuroliya2015-09-261-7/+7
| | | | skip]
* Added nodoc for `arel` method which returns object of private api. [ci skip]Ronak Jangir2015-09-091-1/+1
|
* Added docs for CollectionProxy#take [ci skip]Ronak Jangir2015-08-231-0/+25
|