aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_proxy.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Add missing method name to exception descriptionMehmet Emin İNAÇ2015-07-201-1/+1
|
* [ci skip] Fix typo in #any? RDocAndrii Ponomarov2015-07-171-1/+1
|
* [ci skip] fix the `collection.clear` guideRoque Pinel2015-06-021-7/+8
| | | | | | | | | | | Improve the guide about `has_many` `collection.clear` to indicate the behavior for each dependent strategy according to `collection.delete_all`. Based on #17179, I changed the `collection.delete` docs to also clarify the default strategy for each `hm` and `hm:t` associations. Fixes #20170.
* Updated documentation of CollectionProxy#clear [ci skip]Prathamesh Sonpatki2015-03-061-0/+3
| | | | | | | | - CollectionProxy#clear method calls delete_all so the SQL is directly run into the database. - So the updated_at column of the object on which its run is not updated. - Closes #17161
* Preserve Array#take(n) behaviour of HasManyAssociationAkira Matsuda2015-02-281-2/+2
|
* Merge branch 'rm-take' into 4-1-stableRafael Mendonça França2015-02-201-0/+4
|
* Remove support to activerecord-deprecated_findersRafael Mendonça França2015-01-021-4/+2
|
* Ensure `first!` and friends work on loaded associationsSean Griffin2014-12-291-0/+1
| | | | Fixes #18237
* Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-1/+1
| | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* [ci skip] Clarify deletion strategies for collection proxieseileencodes2014-10-041-17/+14
| | | | | | | | | | | For detailed testing of behavior see: https://gist.github.com/eileencodes/5b0a2fe011dcff6203fe This shows destroy_all always destroys records and fires callbacks. It will never use nullify or delete_all delete_all's behavior varies greatly based on `hm` vs `hm:t` and deletion strategy.
* [ci skip] Updated documentation syntax of other parameter for rdocTom Kadwill2014-08-271-1/+1
|
* Merge pull request #16705 from tomkadwill/documented_many_block_paramZachary Scott2014-08-261-1/+1
|\ | | | | [ci skip] Updated documentation syntax of block parameter for rdoc