aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* Fix undefined method `owners' for NullPreloader:ClassLadislav Smola2016-04-061-0/+14
| | | | | | | | | | | | | | * 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]
* Merge pull request #22518 from ↵Arthur Nogueira Neves2016-03-181-0/+17
|\ | | | | | | | | 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-0/+17
| | | | | | | | relations
* | don't treat all associations with extensions as instance dependent.Yves Senn2016-03-031-0/+12
| | | | | | | | | | | | | | | | | | | | 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.
* | Remove duplicated `test_` prefix [ci skip]Ryuta Kamizono2016-03-021-1/+1
| |
* | Respect through association scopes when used with polymorphicSean Griffin2016-02-291-0/+7
| | | | | | | | | | | | | | | | | | | | | | When the `source_type` option is passed to a has_many through, the resulting `Reflection` will be an instance of `PolymorphicReflection` and not `ThroughReflection`, meaning that it will ignore the scopes that it needs to apply from the through reflections. This adds an additional delegation call to remedy this. I've been finding the reflection code completely impenetrable lately, it could use some major love. Fixes #22726
* | Merge pull request #18766 from yasyf/issue_17864Sean Griffin2016-02-291-0/+32
|\ \ | | | | | | | | | | | | 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-021-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-224-10/+10
| | |
* | | fix typoLobsiinvok2016-02-201-1/+1
| | |
* | | eliminate warnings about multiple primary keys on habtm join tablesAaron Patterson2016-02-191-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | 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
* | | 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
| | |
* | | Typos in AR testsAkira Matsuda2016-02-041-1/+1
| | |
* | | Typos in AR testsAkira Matsuda2016-02-032-6/+6
| | |
* | | Merge pull request #20997 from himesh-r/issue-20995Arthur Neves2016-02-021-1/+1
|\ \ \ | |_|/ |/| | | | | | | | 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/+1
| | | | | | | | | | | | | | | | | | key #20995 Changed id-writer to save join table records based on association primary key
* | | Revert "Merge pull request #22486 from ↵Yves Senn2015-12-211-17/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+17
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Pass group values when including association Conflicts: activerecord/CHANGELOG.md
| * | | Pass SQL group by values when including scoped associationLucjan Suski2015-12-151-0/+13
| | | | | | | | | | | | | | | | | | | | Fixes problem when added `group()` in association scope was lost in eager loaded association.
* | | | Merge pull request #19423 from ↵Aaron Patterson2015-12-181-0/+6
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | 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-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | For performance, Avoid instantiate CollectionProxy. Fixes #12537
* | | | | Remove legacy mysql adapterAbdelkader Boudih2015-12-171-1/+1
| |/ / / |/| | |
* | | | Bugfix collection association #create method …Bogdan Gusiev2015-11-231-0/+6
| | | | | | | | | | | | | | | | | | | | When same association is loaded in the model creation callback The new object is inserted into association twice
* | | | Except keys of `build_record`'s argument from `create_scope` in ↵yui-knk2015-11-161-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialize_attributes If argument of `build_record` has key and value which is same as default value of database, we should also except the key from `create_scope` in `initialize_attributes`. Because at first `build_record` initialize record object with argument of `build_record`, then assign attributes derived from Association's scope. In this case `record.changed` does not include the key, which value is same as default value of database, so we should add the key to except list. Fix #21893.
* | | | Merge pull request #22125 from k0kubun/left_joinsSean Griffin2015-10-301-0/+5
|\ \ \ \ | | | | | | | | | | Alias left_joins to left_outer_joins
| * | | | Alias left_joins to left_outer_joinsTakashi Kokubun2015-10-311-0/+5
| | | | |
* | | | | Fix test failures caused by #12071Sean Griffin2015-10-301-10/+10
|/ / / / | | | | | | | | | | | | | | | | | | | | This assumes only one query was ever executed, but it appears to sometimes be loading schema information. We can just look at the array of queries, rather than the "first" one that was run
* | | | Merge pull request #12071 from Crunch09/outer_joinsSean Griffin2015-10-301-0/+74
|\ \ \ \ | | | | | | | | | | | | | | | added ActiveRecord::Relation#outer_joins
| * | | | added ActiveRecord::Relation#left_outer_joinsFlorian Thomas2015-05-191-0/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Example: User.left_outer_joins(:posts) => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" = "users"."id"
* | | | | Ensure `has_and_belongs_to_many` works with `belongs_to_required_by_default`Sean Griffin2015-10-291-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, if `ActiveRecord::Base.belongs_to_required_by_default` is set to `true`, then creating a record through `has_and_belongs_to_many` fails with the cryptic error message `Left side must exist`. This is because `inverse_of` isn't working properly in this case, presumably since we're doing trickery with anonymous classes in the middle. Rather than following this rabbit hole to try and get `inverse_of` to work in a case that we know is not publicly supported, we can just turn off this validation to match the behavior of 4.2 and earlier.
* | | | | Never pass `nil` to `order`Sean Griffin2015-10-291-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-18/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e, reversing changes made to ec94f00ba3cf250eb54fc5b7a5e3ed4b90164f34. This pull request broke the build.
* | | | | Merge pull request #19501 from ccutrer/dry_sti_subclass_finding2Sean Griffin2015-10-291-2/+2
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | DRY up STI subclass logic
| * \ \ \ \ Fix merge conflicts from #19501Sean Griffin2015-10-291-2/+2
| |\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm making this commit separately because this has failing tests and style nitpicks that I'd like to make as individual commits, to make the changes I'm making explicit. We still want a single merge commit at the end, however.
| | * | | | | DRY up STI subclass logicCody Cutrer2015-03-241-2/+2
| | | |/ / / | | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the newer method used for discriminating new records did not use the older and more robust method used for instantiating existing records, but did have a better post-check to ensure the sublass was in the hierarchy. so move the descendants check to find_sti_class, and then simply call find_sti_class from subclass_from_attributes now with fixed specs
* | / | | | Set `scope.reordering_value` to `true` if :reordering values are specifiedakihiro172015-10-301-0/+18
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | We should call `scope.order!` and set `scope.reordering_value` to `true` if :reordering values are specified Fixes #21886
* | | | | Merge pull request #18548 from ↵Sean Griffin2015-10-281-0/+41
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sebjacobs/support-bidirectional-destroy-dependencies Add support for bidirectional destroy dependencies
| * | | | | Add support for bidirectional destroy dependenciesSeb Jacobs2015-01-161-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit if you defined a bidirectional relationship between two models with destroy dependencies on both sides, a call to `destroy` would result in an infinite callback loop. Take the following relationship. class Content < ActiveRecord::Base has_one :content_position, dependent: :destroy end class ContentPosition < ActiveRecord::Base belongs_to :content, dependent: :destroy end Calling `Content#destroy` or `ContentPosition#destroy` would result in an infinite callback loop. This commit changes the behaviour of `ActiveRecord::Callbacks#destroy` so that it guards against subsequent callbacks. Thanks to @zetter for demonstrating the issue with failing tests[1]. [1] rails#13609
* | | | | | Merge pull request #18383 from ↵Rafael Mendonça França2015-10-271-0/+19
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | scambra/habtm-with-where-includes-16032-for-master Includes HABTM returns correct size now
| * | | | | | Includes HABTM returns correct size now. It's caused by the join dependencySergio Cambra2015-01-071-0/+19
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | only instantiates one HABTM object because the join table hasn't a primary key. Updated commit from @bigxiang commit dbaa837 Fixes #16032. Examples: before: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 1 after: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 3
* | | | | | Tweaked wording used in some tests.Sebastian McKenzie2015-10-251-4/+4
| | | | | |
* | | | | | Fix merge conflicts for #19938Sean Griffin2015-10-201-0/+12
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a separate commit, as it is not just a changelog conflict. Want to point out the changes in the code
| * | | | | | Fix for activerecord join dependency instantiate bugMehmet Emin İNAÇ2015-05-041-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | use only object_id instead parent class and parent id test cases assert_equal use table name in references fix minor problems
* | | | | | | Reorder application of has_many association constraints.jbranchaud2015-10-191-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With `unscope!` called last, it undoes `where` constraints of the same value when the `where` is chained after the `unscope`. This is what a `rewhere` does. This is undesirable behavior. The included tests demonstrate both the `unscope(...).where(...)` behavior as well as the direct use of `rewhere(...)`. This is in reference to #21955.
* | | | | | | Fix regression in inverse_of on through associationseileencodes2015-09-261-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `inverse_of` on through associations was accidently removed/caused to stop working in commit f8d2899 which was part of a refactoring on `ThroughReflection`. To fix we moved `inverse_of` and `check_validity_of_inverse!` to the `AbstractReflection` so it's available to the `ThroughReflection` without having to dup any methods. We then need to delegate `inverse_name` method in `ThroughReflection`. `inverse_name` can't be moved to `AbstractReflection` without moving methods that set the instance variable `@automatic_inverse_of`. This adds a test that ensures that `inverse_of` on a `ThroughReflection` returns the correct class name, and the correct record for the inverse relationship. Fixes #21692
* | | | | | | Merge pull request #21550 from didacte/unscope-associationsSean Griffin2015-09-241-0/+21
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | ActiveRecord: use association's `unscope` when preloading
| * | | | | | | Include association's `unscope` when preloadingJimmy Bourassa2015-09-091-0/+21
| | | | | | | |
* | | | | | | | Don't rely on subsecond precision being applied in testsSean Griffin2015-09-232-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When I originally reviewed the #20317, I believe these changes were present, but it appears that it was later updated so that they were removed. Since Travis hadn't re-run the build, this slipped through.