aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Remove unnecessary `set_inverse_instance` in finder methodsRyuta Kamizono2016-08-021-6/+2
| | | | | | | Because `scope` (`target_scope`) is a `AssociationRelation`. `AssociationRelation` handles `set_inverse_instance`. https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/association_relation.rb#L31-L33
* 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
| |
* | Merge pull request #25940 from kamipo/fix_collection_proxy_loadRafael França2016-07-281-0/+6
|\ \ | | | | | | Fix to `CollectionProxy#load` does `load_target`
| * | Fix to `CollectionProxy#load` does `load_target`Ryuta Kamizono2016-07-251-0/+6
| |/
* | Remove circular join references in join_dependencyTakashi Kokubun2016-07-281-1/+3
| | | | | | | | Fixes #25653.
* | `load_target` is a public methodRyuta Kamizono2016-07-231-1/+1
|/ | | | `send` is unnecessary.
* Add `exists?` and `update_all` to `CollectionProxy` for respects an ↵Ryuta Kamizono2016-07-201-5/+1
| | | | | | association scope Fixes #25732.
* Merge pull request #25578 from ↵Rafael França2016-07-201-2/+4
|\ | | | | | | | | kamipo/move_warning_about_composite_primary_key_to_attribute_methods_primary_key Move the warning about composite primary key to `AttributeMethods::PrimaryKey`
| * Move the warning about composite primary key to `AttributeMethods::PrimaryKey`Ryuta Kamizono2016-07-021-2/+4
| | | | | | | | | | | | | | | | | | | | | | Actually schema dumper/creation supports composite primary key (#21614). Therefore it should not show the warning about composite primary key in connection adapter. This change moves the warning to `AttributeMethods::PrimaryKey` and suppress the warning for habtm join table. Fixes #25388.
* | [ci skip] fix a typoYamaguchi.Tomoki2016-07-151-1/+1
| |
* | Fixed unnecessary nesting in handle_dependencyHerman Hiddema2016-07-041-7/+5
|/ | | | | This nested if checked the same value as the containing case statement. Moved the code in the if/else into when/else in the containing case.
* Exists shouldn't error when used with `includes`Sean Griffin2016-05-301-2/+4
| | | | | | | | | | | | | | | | Currently `exists?` does some hackery where it assumes that we can join onto anything that we passed to `eager_load` or `includes`, which doesn't work if we are joining onto a polymorphic association. Actually figuring out if we want to include something would require knowledge deep within the join dependency module, which is hard to pull up. The simplest solution is just to pass a flag down that says we're not actually going to try to eager load any of the data. It's not the solution I'd like, but that code really needs to be untangled before we can do much with it. This is another attempt at 6d5b1fd which should address the concerns that led to reverting it in 4ecabed.
* Merge pull request #24862 from maclover7/jm-ar-fixesRafael França2016-05-211-2/+2
|\ | | | | Add missing `the`
| * Add missing `the`Jon Moss2016-05-211-2/+2
| | | | | | | | [ci skip]
* | Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-182-4/+4
| | | | | | | | | | | | | | | | 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.
* | Merge pull request #24203 from sferik/count_with_blockKasper Timm Hansen2016-05-162-5/+14
|\ \ | | | | | | Forward ActiveRecord::Relation#count to Enumerable#count if block given
| * | Forward ActiveRecord::Relation#count to Enumerable#count if block givenErik Michaels-Ober2016-03-192-5/+14
| | |
* | | Give more context from `AssociationMismatchError`Sean Griffin2016-05-121-1/+2
| | | | | | | | | | | | | | | | | | | | | The error message that we give today makes this error difficult to debug if you receive it. I have no clue why we're printing the object ID of the class (the commit doesn't give context), but I've left it as it was deliberate.
* | | Replacement cycle for readabilityMolchanov Andrey2016-05-101-2/+1
| |/ |/|
* | Fix counter_cache double increment bugTom Kadwill2016-04-282-0/+3
| |
* | Allow symbols using "dot notation" to be passed to whereSean Griffin2016-04-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 04ac5655be91f49cd4dfe2838df96213502fb274 I assumed that we would never want to pass the "table_name.column_name" form to where with a symbol. However, in Ruby 2.2 and later, you can quote symbols using the new hash syntax, so it's a semi-reasonable thing to do if we want to support the dot notation (which I'd rather deprecate, but that would be too painful of a migration). Instead we've changed the definition of "this is a table name with a dot" to when the value associated is a hash. It would make very little sense to write `where("table_name.column_name": { foo: :bar })` in any scenario (other than equality for a JSON column which we don't support through `where` in this way). Close #24514.
* | 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]
* | Ensure associations still work when the table name contains a dotSean Griffin2016-03-311-2/+2
|/ | | | | | | | | | | | | | | This issue occured because associations now call `where` directly, and a dot in the key name for `where` means nested tables. For this fix, we now pass the table name as a symbol, and do not attempt to expand symbols containing a dot. This is a temporary fix. I do not think we should support table names containing a dot, as it has a special meaning in most backends, as well as most APIs that involve table names. This commit does not include a test, as I am going to deprecate table names containing dots in the following commit. Fixes #24367
* Merge pull request #22518 from ↵Arthur Nogueira Neves2016-03-181-1/+1
|\ | | | | | | | | RochesterinNYC/better-error-message-for-includes-relations-missing Improve error message for missing relations for includes and eager_load
| * Improve clarity of error message for missing includes and eager_loadJames Wen2016-01-281-1/+1
| | | | | | | | relations
* | start hiding the `scope_chain` data structureAaron Patterson2016-03-041-1/+1
| | | | | | | | | | Introduce a predicate method that doesn't need to build a scope chain, but also hides the data structure used for representing the scope chain.
* | don't treat all associations with extensions as instance dependent.Yves Senn2016-03-031-1/+5
| | | | | | | | | | | | | | | | | | | | Closes #23934. This is a forward port of ac832a43b4d026dbad28fed196d2de69ec9928ac Previously the scope of all associations with extensions were wrapped in an instance dependent proc. This made it impossible to preload such associations.
* | 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.
* | | Merge pull request #23794 from matthewd/mutation-safe-to_aMatthew Draper2016-02-212-1/+5
|\ \ \ | | | | | | | | | | | | Mutating the result of Relation#to_a should not affect the relation
| * | | Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-212-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* | | | eliminate warnings about multiple primary keys on habtm join tablesAaron Patterson2016-02-191-0/+3
|/ / / | | | | | | | | | | | | | | | | | | | | | habtm join tables commonly have two id columns and it's OK to make those two id columns a primary key. This commit eliminates the warnings for join tables that have this setup. ManageIQ/manageiq#6713
* | | Merge pull request #18109 from k0kubun/unscoped-joinsSean Griffin2016-02-111-6/+12
|\ \ \ | | | | | | | | | | | | | | | | | | | | Allow `joins` to be unscoped Fixes #13775
| * | | Allow `joins` to be unscopedTakashi Kokubun2016-01-311-6/+12
| | |/ | |/|
* | | rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-102-8/+8
| | |
* | | allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-092-0/+18
| | |
* | | Merge pull request #23457 from matthewd/arel-attributeMatthew Draper2016-02-042-2/+2
|\ \ \ | | | | | | | | Defer Arel attribute lookup to the model class
| * | | Defer Arel attribute lookup to the model classMatthew Draper2016-02-042-2/+2
| |/ / | | | | | | | | | | | | 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.
* | | Merge pull request #20997 from himesh-r/issue-20995Arthur Neves2016-02-021-1/+4
|\ \ \ | |/ / |/| | | | | | | | Changed id-writer to save join table records based on association primary key #20995.
| * | Changed id-writer to save join table records based on association primary ↵Himesh2016-02-021-1/+4
| | | | | | | | | | | | | | | | | | key #20995 Changed id-writer to save join table records based on association primary key
* | | Add missing source_type if provided on hmt which belongs to an sti recordVipul A M2016-01-241-0/+5
| | | | | | | | | | | | Fixes #23209
* | | Define `:foreign_type` as a valid option in `SingularAssociation`yui-knk2016-01-193-3/+3
| | | | | | | | | | | | | | | `:foreign_type` is a valid option for `belongs_to` and `has_one` so remove this to `SingularAssociation`.
* | | `substitute_at` is no longer usedRyuta Kamizono2016-01-141-2/+1
| | | | | | | | | | | | Arel handles substitution for bind parameters by now.
* | | 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
* | | | Make sure we touch all the parents when touch_later.Arthur Neves2015-12-061-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was that when saving an object, we would call touch_later on the parent which wont be saved immediteally, and it wont call any callbacks. That was working one level up because we were calling touch, during the touch_later commit phase. However that still didnt solve the problem when you have a 3+ levels of parents to be touched, as calling touch would affect the parent, but it would be too late to run callbacks on its grand-parent. The solution for this, is instead, call touch_later upwards when the first touch_later is called. So we make sure all the timestamps are updated without relying on callbacks. This also removed the hard dependency BelongsTo builder had with the TouchLater module. So we can still have the old behaviour if TouchLater module is not included. [fixes 5f5e6d924973003c105feb711cefdb726f312768] [related #19324]