aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
...
* | | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-293-13/+13
| | |
* | | Merge PR #19759Arthur Neves2016-10-281-1/+4
|\ \ \ | | | | | | | | | | | | Fix for has_and_belongs_to_many & has_many_through associations
| * | | Fix for has_and_belongs_to_many & has_many_through associations while ↵Mehmet Emin İNAÇ2016-02-131-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | partial_writes is false This will fix #19663 Also with this fix, active record does not fire unnecassary update queries while partial_writes is true
* | | | Fix HABTM associations join table resolver bug on constants and symbolsMehmet Emin İNAÇ2016-10-271-1/+1
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using Constant and symbol class_name option for associations are valid but raises exception on HABTM associations. There was a test case which tries to cover symbol class_name usage but doesn't cover correctly. Fixed both symbol usage and constant usage as well. These are all working as expected now; ``` has_and_belongs_to_many :foos, class_name: 'Foo' has_and_belongs_to_many :foos, class_name: :Foo has_and_belongs_to_many :foos, class_name: Foo ``` Closes #23767
* | | 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`.
* | Don't skip in-memory insertion of associations when loaded in validateSean Griffin2016-09-292-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was caused by 6d0d83a33f59d9415685852cf77818c41e2e2700. While the bug it's trying to fix is handled if the association is loaded in an after_(create|save) callback, it doesn't handle any cases that load the association before the persistence takes place (validation, or before_* filters). Instead of caring about the timing of persistence, we can just ensure that we're not double adding the record instead. The test from that commit actually broke, but it was not because the bug has been re-introduced. It was because `Bulb` in our test suite is doing funky things that look like STI but isn't STI, so equality comparison didn't happen as the loaded model was of a different class. Fixes #26661.
* | Merge pull request #26448 from kamipo/remove_collection_association_uniqKasper Timm Hansen2016-09-181-1/+0
|\ \ | | | | | | Remove unnecessry `alias uniq distinct` for collection association
| * | Remove unnecessry `alias uniq distinct` for collection associationRyuta Kamizono2016-09-101-1/+0
| | | | | | | | | | | | `CollectionAssociation` is internal class and `uniq` is not called.
* | | 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.
* | Merge pull request #26380 from kamipo/pass_set_inverse_instance_blockKasper Timm Hansen2016-09-081-2/+2
|\ \ | | | | | | Pass `set_inverse_instance` block to `sc.execute` for `SingularAssociation`
| * | Pass `set_inverse_instance` block to `sc.execute` for `SingularAssociation`Ryuta Kamizono2016-09-031-2/+2
| | | | | | | | | | | | | | | | | | | | | Follow up to caa178c. caa178c updated all code which sets inverse instances on newly loaded associations to use block. But `SingularAssociation` was forgotten it.
* | | Revert " [ci skip] Remove duplicate example."Vipul A M2016-09-061-0/+5
| | |
* | | Merge pull request #26410 from aditya-kapoor/rm-dupsVipul A M2016-09-061-5/+0
|\ \ \ | | | | | | | | [ci skip] Remove duplicate example.
| * | | [ci skip] Remove duplicate example.Aditya Kapoor2016-09-061-5/+0
| | | |
* | | | Remove redundant `!loaded?` conditionRyuta Kamizono2016-09-061-2/+2
| | | | | | | | | | | | | | | | | | | | Already checked `if !find_target? || loaded?`, unnecessary `!loaded?` in elsif condition.
* | | | 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
| | | |
* | | | Remove unnecessary `count` method for collection proxyRyuta Kamizono2016-09-042-36/+14
| | | | | | | | | | | | | | | | Simply use its own method because `CollectionProxy` inherits `Relation`.
* | | | Extract duplicated `create` and `create!` definition for associationRyuta Kamizono2016-09-033-16/+8
| |/ / |/| |
* | | fixes remaining RuboCop issues [Vipul A M, Xavier Noria]Xavier Noria2016-09-012-3/+3
| | |
* | | Ensure that inverse associations are set before running callbacksSean Griffin2016-08-316-13/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | Remove unnecessary `any?` and `many?` methods for collection proxyRyuta Kamizono2016-08-192-28/+12
| | | | | | | | | | | | Simply use its own methods because `CollectionProxy` inherits `Relation`.
* | | Remove unnecessary `length` method for collection proxyRyuta Kamizono2016-08-192-12/+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-192-11/+6
|\ \ \ | | | | | | | | | | | | | | | | kamipo/remove_unnecessary_select_for_collection_proxy Remove unnecessary `select` method for `CollectionProxy`
| * | | Remove unnecessary `select` method for `CollectionProxy`Ryuta Kamizono2016-08-182-11/+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
* | | | Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-182-2/+6
|\ \ \ \ | | | | | | | | | | | | | | | Preserve readonly flag only for readonly association
| * | | | Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-302-2/+4
| | | | | | | | | | | | | | | | | | | | Fixes #24093
* | | | | Remove unnecessary ordinal methods for collection associationRyuta Kamizono2016-08-182-91/+74
| |/ / / |/| | | | | | | | | | | | | | | 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-162-40/+38
| |_|/ / |/| | | | | | | | | | | | | | | | | | | | | | | `#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-142-15/+11
| | | | | | | | | | | | | | | | | | | | `#first`, `#second`, ..., `#last` methods respects dirty target. But `#take` doesn't respect it. This commit fixes the inconsistent behavior.
* | | | code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* | | | revises most Lint/EndAlignment offensesXavier Noria2016-08-071-5/+5
| | | | | | | | | | | | | | | | Some case expressions remain, need to think about those ones.
* | | | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| | | |
* | | | applies remaining conventions across the projectXavier Noria2016-08-068-26/+16
| | | |
* | | | normalizes indentation and whitespace across the projectXavier Noria2016-08-069-391/+391
| | | |
* | | | modernizes hash syntax in activerecordXavier Noria2016-08-065-7/+7
| | | |
* | | | applies new string literal convention in activerecord/libXavier Noria2016-08-069-20/+20
|/ / / | | | | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | | Avoid duplicated `set_inverse_instance` for target scopeRyuta Kamizono2016-08-033-23/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 See also #26022.
* | | 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.