aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_proxy.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #36320 from XrXr/no-doc-prependRafael França2019-05-211-1/+1
|\ | | | | [CI skip] Put :nodoc: on method that raises NoMethodError
| * Put :nodoc: on method that raises NoMethodErrorAlan Wu2019-05-211-1/+1
| | | | | | | | | | This method is not intended to be used so I think we should remove it from the docs.
* | Fix rdoc rendering for push alias symbolTenzin Chemi2019-04-231-1/+1
|/
* Clarify collection proxy docsGannon McGibbon2019-02-081-11/+8
| | | | | | | | | The docs for `ActiveRecord::Associations::CollectionProxy` describe `ActiveRecord::Associations::Association`. I've moved them to association and rewrote collection proxy's docs to be more applicable to what the class actually does.` [ci skip]
* Fix `CollectionProxy#concat` to return self by alias it to `#<<`Yuya Tanaka2019-02-061-30/+4
| | | | Formerly it was returning arguments (`records` array).
* Reset scope after collection deleteGannon McGibbon2018-12-041-4/+4
| | | | | Reset scope after delete on collection association to clear stale offsets of removed records.
* Don't expose internal `get_value`/`set_value` methodsRyuta Kamizono2018-10-181-1/+1
|
* Clear QueryCache when reloading associationsChristophe Maximin2018-10-101-1/+1
|
* Revert "✂️"Ryuta Kamizono2018-02-071-1/+2
| | | | | | | | This reverts commit 487a1061cc496455dfe5ee84d1e49d509c1675b5. This `#--` is necessary for the doc of `distinct`. [ci skip]
* ✂️schneems2018-02-061-2/+1
|
* Avoid passing unnecessary arguments to relationDaniel Colson2018-01-241-1/+1
| | | | | | | | | | | | Most of the time the table and predicate_builder passed to Relation.new are exactly the arel_table and predicate builder of the given klass. This uses klass.arel_table and klass.predicate_builder as the defaults, so we don't have to pass them in most cases. This does change the signaure of both Relation and AssocationRelation. Are we ok with that?
* Consolidate duplicated `to_ary`/`to_a` definitions in `Relation` and ↵Ryuta Kamizono2017-11-101-4/+6
| | | | `CollectionProxy`
* 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
|/