aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* `preloaded_records` no longer includes `nil` since #35496Ryuta Kamizono2019-04-051-1/+0
|
* Fix preloader to never reset associations in case they are already loadedBogdan Gusiev2019-03-071-5/+11
| | | | | | | | | | | | | | This patch fixes the issue when association is preloaded with a custom preload scope which disposes the already preloaded target of the association by reseting it. When custom preload scope is used, the preloading is now performed into a separated Hash - #records_by_owner instead of the association. It removes the necessaty the reset the association after the preloading is complete so that reset of the preloaded association never happens. Preloading is still happening to the association when the preload scope is empty.
* Restore `preloaders_for_one` methodRyuta Kamizono2018-10-051-5/+9
| | | | Since the above comment is for the `preloaders_for_one`.
* ActiveRecord::Associations::Preloader should not fail to preload through ↵Nikita Sokolov2018-10-021-28/+24
| | | | missing records
* If association is a hash-like object preloading failsBohdan Pohorilets2018-09-261-4/+3
| | | | | | If you pass a hash-like object to preload associations (for example ActionController::Parameters) preloader will fail with the ArgumentError. This change allows passing objects that may be converted to a Hash or String into a preloader
* ActiveRecord::Associations::Preloader should preload all instances of the ↵Nikita Sokolov2018-09-161-1/+0
| | | | same record
* Can preload associations through polymorphic associationsDana Sherson2018-04-201-10/+15
|
* Use private attr_readerRyuta Kamizono2018-02-231-1/+1
| | | | | Since #32028, Rails 6 requires Ruby 2.3+. No longer needed workaround for Ruby 2.2 "private attribute?" warning.
* Bring back passing single record support for `Preloader`Ryuta Kamizono2018-01-101-1/+1
| | | | | | | | | | I removed redundant `Array.wrap(records)` since `Preloader` is nodoc class and Active Record always pass `records` as an array to `Preloader`. But if users relies on that behavior, it is not worth dropping its behavior. Fixes #31661.
* Remove useless preloader classesRyuta Kamizono2017-11-101-19/+7
| | | | | | | | | They are only different by one line of code which doesn't deserve a hierarchy of 7 classes. Closes #31079. [Ryuta Kamizono & Bogdan Gusiev]
* Don't expose accessors which are internal used onlyRyuta Kamizono2017-11-081-2/+3
|
* Early return if `records.empty?` in `Preloader#preload`Ryuta Kamizono2017-09-181-3/+3
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Fix preloading association with scope including joinsRyuta Kamizono2017-07-041-3/+0
|
* 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
|
* Skip instantiating `NullPreloader` if `assoc.klass` is nilRyuta Kamizono2017-06-271-11/+3
| | | | | Simply we can skip instantiating `NullPreloader` if `assoc.klass` is nil.
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-17/+17
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-67/+67
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-10/+10
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix undefined method `owners' for NullPreloader:ClassLadislav Smola2016-04-061-0/+1
| | | | | | | | | | | | | | * Fix undefined method `owners' for NullPreloader:Class Fixing undefined method `owners' for ActiveRecord::Associations::Preloader::NullPreloader:Class * Use Ruby 1.9 hash format Use Ruby 1.9 hash format #24192 [Rafael Mendonça França + Ladislav Smola]
* [ci skip] Add doc for preloader_forschneems2015-10-261-0/+4
|
* [ci skip] Clarify doc for preloaders_for_oneschneems2015-10-261-0/+5
|
* [ci skip] Add doc to preloaders_onschneems2015-10-261-0/+1
|
* [ci skip] Fix method documentation locationschneems2015-10-261-3/+2
|
* Correct error message in Standard American english and add a test case for ↵prakash2015-08-181-1/+1
| | | | the same.
* docs, nodoc `NullPreloader` and `AlreadyLoaded`.Yves Senn2015-06-291-2/+2
| | | | | These classes are part of Active Record Preloader, which is not part of the public API.
* Merge pull request #20673 from aditya-kapoor/correct-preload-docYves Senn2015-06-231-1/+1
|\ | | | | | | [ci skip] correct for ActiveRecord::Associations::Preloader
| * [ci skip] correct for ActiveRecord::Associations::Preloader:Aditya Kapoor2015-06-231-1/+2
| |
* | docs, add missing closing bracket. [ci skip]Yves Senn2015-06-231-1/+1
|/
* Don't rely on the internal representation of join valuesSean Griffin2015-01-271-1/+1
| | | | | I'm going to be extracting this logic into a clause class, things need to go through a method and not access the values hash directly.
* Remove all references to `where_values` in association codeSean Griffin2015-01-251-1/+1
|
* Don't rely as much on the structure of the values hash in associationsSean Griffin2015-01-251-1/+1
| | | | | | | | | The structure of `values[:where]` is going to change, with an intermediate definition of `where_values` to aid the refactoring. Accessing `values[:where]` directly messes with that, signficantly. The array wrapping is no longer necessary, since `where_values` will always return an array.
* Adds preloaded_records method to NullPreloaderThorsten Ball2014-11-281-0/+1
| | | | | | | | This fixes a regression where preloading association throws an exception if one of the associations in the preloading hash doesn't exist for one record. Fixes #16070
* Updating Associations::Preloader docsJack Danger Canty2014-08-171-23/+32
| | | | | | | | | Much of the previous documentation introduced features new in 2011. This commit refreshes it to provide clearer code examples and spends more time describing the normal case (preloaded associations) and less time describing the fallback. [ci skip]
* Skip if the association was already loaded.Zachary Scott2014-05-241-0/+1
|
* fix multiple hash preloads. Fixes #14994Aaron Patterson2014-05-201-6/+7
|
* deprecate, join, preload, eager load of instance dependent associations.Yves Senn2014-05-101-0/+1
| | | | | | | Closes #15024. These operations happen before instances are created. The current behavior is misleading and can result in broken behavior.
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-071-29/+6
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * Simplify Preloader#grouped_records code.thedarkone2014-03-301-20/+6
| | | | | | | | | | | | The new method relies on AR::Associations::Association knowing about both reflection and a model class. AR::Base#association now raises a descriptive error when trying to access non-existent associations. Previously it would blow up with a confusing NoMethodError: undefined method `association_class' for nil:NilClass.
| * Fix polymorphic preloads on NOT NULL _type columns.thedarkone2014-03-301-10/+1
| | | | | | | | Defer to Association#klass instead of having a custom/duplicate code.
* | Merge branch 'master' into set_bindsAaron Patterson2014-01-111-42/+77
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (2794 commits) doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip] Restore DATABASE_URL even if it's nil in connection_handler test [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users Ensure Active Record connection consistency Revert "ask the fixture set for the sql statements" Check `respond_to` before delegation due to: https://github.com/ruby/ruby/commit/d781caaf313b8649948c107bba277e5ad7307314 Adding Hash#compact and Hash#compact! methods MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users. clear cache on body close so that cache remains during rendering add a more restricted codepath for templates fixes #13390 refactor generator tests to use block form of Tempfile Fix typo [ci skip] Move finish_template as the last public method in the generator Minor typos fix [ci skip] make `change_column_null` reversible. Closes #13576. create/drop test and development databases only if RAILS_ENV is nil Revert "Speedup String#to" typo fix in test name. [ci skip]. `core_ext/string/access.rb` test what we are documenting. Fix typo in image_tag documentation ... Conflicts: activerecord/lib/active_record/associations/join_dependency/join_association.rb activerecord/lib/active_record/relation/query_methods.rb
| * https://github.com/rails/rails/commit/2075f39d726cef361170218fd16421fc52bed5 ↵Vipul A M2013-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a8 introduced a regression in includes/preloades by calling `read_attribute` on an association when preloading takes places, instead of using loaded records in `association.target`. tl;dr Records are not made properly available via `read_attribute` when preloding in simultaneous, but value of `@loaded` is already set true, and records concatenated in `association.target` on an association object. When `@loaded` is true we return an object of `AlreadyLoaded` in preload_for. In `AlreadyLoaded` to return preloaded records we make wrong use of `read_attribute`, instead of `target` records. The regression is fixed by making use of the loaded records in `association.target` when the preloading takes place. Fixes #13437
| * Make missed association exception message more informativePaul Nikitochkin2013-10-131-3/+3
| | | | | | | | | | Add target class name, which should have missed association on preload, into exception message to simplify detecting problem part.
| * remove the HABTM preloaderAaron Patterson2013-10-021-3/+0
| |
| * guarantee that `klass` is not nil inside the preloader objectsAaron Patterson2013-09-241-4/+11
| |
| * eliminate the `loaded?` conditionalAaron Patterson2013-09-241-2/+6
| |
| * push preloaded test up to the factory method so we can eliminateAaron Patterson2013-09-241-2/+17
| | | | | | | | conditionals from the individual preloaded classes
| * pass the preloader down so we only have to construct oneAaron Patterson2013-09-231-2/+4
| |