aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader
Commit message (Collapse)AuthorAgeFilesLines
...
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-292-4/+4
|
* Merge pull request #26379 from kamipo/remove_unnecessary_query_scopeAndrew White2016-09-051-4/+0
|\ | | | | Remove unnecessary `query_scope`
| * Remove unnecessary `query_scope`Ryuta Kamizono2016-08-161-4/+0
| |
* | Ensure that inverse associations are set before running callbacksSean Griffin2016-08-313-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a parent association was accessed in an `after_find` or `after_initialize` callback, it would always end up loading the association, and then immediately overwriting the association we just loaded. If this occurred in a way that the parent's `current_scope` was set to eager load the child, this would result in an infinite loop and eventually overflow the stack. For records that are created with `.new`, we have a mechanism to perform an action before the callbacks are run. I've introduced the same code path for records created with `instantiate`, and updated all code which sets inverse instances on newly loaded associations to use this block instead. Fixes #26320.
* | Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-181-1/+1
|\ \ | |/ |/| | | Preserve readonly flag only for readonly association
| * Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-301-1/+1
| | | | | | | | Fixes #24093
* | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| |
* | applies remaining conventions across the projectXavier Noria2016-08-063-6/+0
| |
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-064-117/+117
|/
* Merge pull request #18766 from yasyf/issue_17864Sean Griffin2016-02-291-8/+15
|\ | | | | | | | | Honour joining model order in `has_many :through` associations when eager loading
| * Honour the order of the joining model in a `has_many :through`Yasyf Mohamedali2015-03-022-9/+16
| | | | | | | | | | | | | | | | | | association when eager loading. Previously, eager loading a `has_many :through` association with no defined order would return the records in the natural order of the database. Now, these records will be returned in the order that the joining record is returned, in case there is a defined order there.
* | Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-1/+1
| | | | | | | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* | Revert "Merge pull request #22486 from ↵Yves Senn2015-12-211-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | methyl/fix-includes-for-groupped-association" This reverts commit 537ac7d6ade61e95f2b70685ff2236b7de965bab, reversing changes made to 9c9c54abe08d86967efd3dcac1d65158a0ff74ea. Reason: The way we preload associations will change the meaning of GROUP BY operations. This is illustrated in the SQL generated by the added test (failing on PG): Association Load: D, [2015-12-21T12:26:07.169920 #26969] DEBUG -- : Post Load (0.7ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" = $1 GROUP BY posts.id ORDER BY SUM(comments.tags_count) [["author_id", 1]] Preload: D, [2015-12-21T12:26:07.128305 #26969] DEBUG -- : Post Load (1.3ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" IN (1, 2, 3) GROUP BY posts.id ORDER BY SUM(comments.tags_count)
* | Merge pull request #22486 from methyl/fix-includes-for-groupped-associationYves Senn2015-12-211-1/+5
|\ \ | | | | | | | | | | | | | | | | | | Pass group values when including association Conflicts: activerecord/CHANGELOG.md
| * | Pass SQL group by values when including scoped associationLucjan Suski2015-12-151-1/+5
| | | | | | | | | | | | | | | Fixes problem when added `group()` in association scope was lost in eager loaded association.
* | | Merge pull request #19423 from ↵Aaron Patterson2015-12-181-2/+7
|\ \ \ | |/ / |/| | | | | | | | yuroyoro/fix_performance_regression_of_preloading_has_many_through_relation Fix #12537 performance regression when preloading has_many_through association
| * | Read already loaded association records from association.targetTomohito Ozaki2015-04-171-2/+7
| |/ | | | | | | | | For performance, Avoid instantiate CollectionProxy. Fixes #12537
* | Never pass `nil` to `order`Sean Griffin2015-10-294-16/+7
| | | | | | | | | | | | | | | | This is part of a refactoring to make it easier to allow `order` to use sanitize like just about everything else on relation. The deleted test doesn't give any reasoning as to why passing `nil` to `order` needs to be supported, and it's rather nonsensical. I can almost see allowing an empty string being passed (though I'm tempted to just disallow it...)
* | Revert "Revert "Merge pull request #22026 from ↵Yves Senn2015-10-291-0/+4
| | | | | | | | | | | | | | | | | | akihiro17/fix-preload-association"" This reverts commit 5243946017d09afff4d70d273b0fcdfd41a4b22a. This fixes an issue with the build where tests would fail on mysql and postgresql due to different ordering.
* | Revert "Merge pull request #22026 from akihiro17/fix-preload-association"Sean Griffin2015-10-291-4/+0
| | | | | | | | | | | | | | This reverts commit 6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e, reversing changes made to ec94f00ba3cf250eb54fc5b7a5e3ed4b90164f34. This pull request broke the build.
* | Set `scope.reordering_value` to `true` if :reordering values are specifiedakihiro172015-10-301-0/+4
| | | | | | | | | | | | We should call `scope.order!` and set `scope.reordering_value` to `true` if :reordering values are specified Fixes #21886
* | Merge pull request #21918 from bogdan/refactor-preloaderSean Griffin2015-10-221-42/+30
|\ \ | | | | | | Refactored association preloader for performance
| * | Refactored association preloader for performanceBogdan Gusiev2015-10-221-42/+30
| | | | | | | | | | | | | | | * less arrays created * less complexity with only one level of nesting in loop
* | | Merge pull request #21033 from dgynn/preloader_build_scope_tuningArthur Nogueira Neves2015-10-041-1/+3
|\ \ \ | |/ / |/| | Skip _select! call unless needed for preloader
| * | skip _select! call unless :select values are specifiedDave Gynn2015-07-261-1/+3
| |/ | | | | | | | | the default scope will select all fields. removing this improves performance and reduces String creation.
* / Include association's `unscope` when preloadingJimmy Bourassa2015-09-091-1/+1
|/
* Remove most type related predicates from `Column`Sean Griffin2015-01-301-2/+2
| | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* Don't rely on the internal representation of join valuesSean Griffin2015-01-271-1/+5
| | | | | 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-252-9/+5
|
* Don't access the where values hash directly in through associationsSean Griffin2015-01-251-1/+1
| | | | See 4d7a62293e148604045a5f78a9d4312e79e90d13 for the reasoning
* 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.
* Return a null column from `column_for_attribute` when no column exists.Rafael Mendonça França2015-01-041-2/+2
| | | | | | | | This reverts commit ae96f229f6501d8635811d6b22d75d43cdb880a4. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods.rb
* Go through normal `where` logic when preloading associationsSean Griffin2014-12-261-1/+1
| | | | | | | | | | This will allow eager type casting to take place as needed. There doesn't seem to be any particular reason that the `in` statement was forced for single values, and the commit message where it was introduced gives no context. See https://github.com/rails/rails/commit/d90b4e2615e8048fdeffc6dffe3246704adee01f
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-8/+2
| | | | on the joined assoiciation
* Merge pull request #17360 from bronzle/includes_and_unscopedYves Senn2014-11-051-0/+1
|\ | | | | | | copy reflection_scopes’s unscoped value when building scope for preloading
| * copy reflection_scopes’s unscoped value when building scope for ↵Byron Bischoff2014-10-221-0/+4
| | | | | | | | preloading, fixes #11036
* | Use bind values for joined tables in where statementsSean Griffin2014-11-011-0/+1
|/ | | | | | | | | | | | | | | In practical terms, this allows serialized columns and tz aware columns to be used in wheres that go through joins, where they previously would not behave correctly. Internally, this removes 1/3 of the cases where we rely on Arel to perform type casting for us. There were two non-obvious changes required for this. `update_all` on relation was merging its bind values with arel's in the wrong order. Additionally, through associations were assuming there would be no bind parameters in the preloader (presumably because the where would always be part of a join) [Melanie Gilman & Sean Griffin]
* Spelling errorsjbsmith862014-08-141-1/+1
|
* `preload` preserves readonly flag on associations. #15853Yves Senn2014-06-251-0/+4
| | | | | | This is a partial fix for #15853. It only works when a `preload` is issued and not an `eager_load`. I've added a skipped failing test-case to keep in mind that we need to deal with `eager_load`.
* Add a deprecation cycle for `NullColumn` from `column_for_attribute`Sean Griffin2014-06-231-2/+2
| | | | | | This is public API, and `simple_form` depends on the `nil` return value. We need to go through a deprecation cycle to return a null object. If people want hash access, they can access the hash.
* Use null column for association key typesSean Griffin2014-06-041-4/+2
|
* Fix regression on eager loading association based on SQL query ratherLauro Caetano2014-06-031-2/+4
| | | | | | than existing column. Fixes #15480.
* Merge pull request #14855 from laurocaetano/fix_polymorphic_with_string_keyYves Senn2014-05-211-4/+25
|\ | | | | | | Fix polymorphic eager load with foreign_key as String.
| * Fix polymorphic eager load with foreign_key as String.Lauro Caetano2014-05-201-2/+17
|/ | | | | | | | | The foreign_key could be `String` and just doing `owners_map[owner_key]` could return `nil`. To prevent this bug, we should `to_s` both keys if their types are different. Fixes #14734.
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-252-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (28 commits) move AR length validation tests into separate test-case. No need for trailing slash on migration path. reset `@arel` when modifying a Relation in place. PostgreSQL Timestamps always map to `:datetime`. [ci skip] Improve formatting and yml Fix a typo in the doc of forty_two AR FinderMethod Improve readability of contributing to rails guide. [ci skip] Precompile the image we're referencing, too. `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions. Fixed an issue with migrating legacy json cookies. Correct comment [ci skip] Perfer to define methods instead of calling test Fix syntax error Add CHANGELOG entry for #14757 [ci skip] Fix run-on sentences and improve grammar [skip ci] Add test for using ActionView::Helpers::FormHelper.label with block and html select! renamed to avoid name collision Array#select! Rearrange deck chairs on the titanic. Organize connection handling test cases. Change favicon_link_tag helper mimetype from image/vnd.microsoft.icon to image/x-icon. ActionController::Renderers documentation fix ...
| * reset `@arel` when modifying a Relation in place.Yves Senn2014-04-241-1/+1
| | | | | | | | /cc @tenderlove
| * select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-211-1/+1
| | | | | | | | | | | | | | | | Fixes #14752 Select mimics the block interface of arrays, but does not mock the block interface for select!. This change moves the api to be a private method, _select!.
* | Merge branch 'master' into adequaterecordAaron Patterson2014-03-131-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (108 commits) make tests pass on Ruby 2.2 Use Sqlite3 adapter in examples use the body proxy to freeze headers just ask the response for the commit status, we do not need to ask the jar only write the jar if the response isn't committed Fix a grammatical error in the i18n guide [ci skip] use method_defined? to check whether or not a method is defined Enhance docs for update_attribute [ci-skip] Change usec to 0 on tests that compare seconds Unit test for mysql quote time usec Changelog entry for mysql56 microseconds Test microsecond on mysql 5.6 MySQL 5.6 and later supports microsecond precision in datetime. [ci skip] Add documentation for original_fullpath. Remove mocking on save, when not necessary comment why we are modifying global state. [ci skip] `change_table` supports `citext`. Follow up to #12523. Removed unnecessary command "application" register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester] Fixes STI when 2+ levels deep. ...
| * Replace map.flatten with flat_map in activerecordErik Michaels-Ober2014-03-031-1/+1
| |