aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-16/+16
|
* Don't update counter cache when through record was not destroyedEugene Kenny2018-01-141-0/+10
| | | | | | When removing a record from a has many through association, the counter cache was being updated even if the through record halted the callback chain and prevented itself from being destroyed.
* Merge pull request #23146 from piotrj/issue_18424Ryuta Kamizono2018-01-111-0/+19
|\ | | | | | | When deleting through records, take into account association conditions
| * When deleting through records, take into account association conditionsPiotr Jakubowski2016-05-041-0/+16
| | | | | | | | | | | | | | | | Fixes #18424. When deleting through records, it didn't take into account the conditions that may have been affecting join model table, but was defined in association definition.
* | Fix `stale_state` for nested `has_many :through` associationsRyuta Kamizono2018-01-101-12/+28
| | | | | | | | Need reloading when through record has replaced.
* | Merge pull request #16314 from ↵Ryuta Kamizono2018-01-101-0/+29
|\ \ | | | | | | | | | | | | | | | zoltankiss/allow-nested-has-many-associations-on-unpersisted-parent-instances fix nested `has many :through` associations on unpersisted parent instances
| * | Fix nested `has many :through` associations on unpersisted instancesZoltan Kiss2015-03-261-0/+29
| | | | | | | | | | | | Fixes: #16313
* | | Add test case for `collection_singular_ids` with symbol primary keysRyuta Kamizono2018-01-011-0/+8
| | | | | | | | | | | | This is a regression test for #27864.
* | | Fix all `s/trough/through/`Ryuta Kamizono2017-10-271-1/+1
| | | | | | | | | | | | | | | | | | | | | ``` % git grep -n trough activerecord/test/cases/associations/has_many_through_associations_test.rb:1253: def test_has_many_trough_with_scope_that_has_joined_same_table_with_parent_relation ```
* | | Fix typo `s/trough/through/`Ryuta Kamizono2017-10-271-1/+1
| | |
* | | fix initial countpavel2017-10-271-0/+4
| | |
* | | Joined tables in association scope doesn't use the same aliases with the ↵Ryuta Kamizono2017-10-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | parent relation's aliases Building association scope in join dependency should respect the parent relation's aliases to avoid using the same alias name more than once. Fixes #30681.
* | | `has_many :through` with unscope should affect to through scopeRyuta Kamizono2017-09-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | The order of scope evaluation should be from through scope to the association's own scope. Otherwise the association's scope cannot affect to through scope. Fixes #13677. Closes #28449.
* | | Through scope should not be affected by scopingRyuta Kamizono2017-08-151-0/+19
| | | | | | | | | | | | | | | | | | Follow up of #29834. Fixes #30266.
* | | Merge pull request #30169 from awortham/awortham/awortham/fix-sql-distinct-bugRafael Mendonça França2017-08-141-0/+26
|\ \ \ | | | | | | | | | | | | Ensure sum honors distinct on has_many through
| * | | Ensure sum honors distinct on has_many throughAaron Wortham2017-08-141-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | When using a has_many through relation and then summing an attribute the distinct was not being used. This will ensure that when summing an attribute, the number is only used once when distinct has been used.
* | | | Fix `reflection.association_primary_key` for `has_many` associationsRyuta Kamizono2017-08-131-14/+0
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is incorrect to treat `options[:primary_key]` as `association_primary_key` if `has_many` associations because the `:primary_key` means the column on the owner record, not on the association record. It will break `ids_reader` and `ids_writer`. ```ruby people(:david).essay_ids # => ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'essays.first_name' in 'field list': SELECT `essays`.first_name FROM `essays` WHERE `essays`.`writer_id` = 'David' ``` Fixes #14439.
* | | Merge pull request #29720 from gaurish/ar_find_error_message_improvementRafael França2017-08-111-2/+4
|\ \ \ | | | | | | | | Return Not found Ids in ActiveRecord::NotFound
| * | | Return Not found Ids in ActiveRecord::NotFoundGaurish Sharma2017-07-291-2/+4
| | | | | | | | | | | | | | | | | | | | This builds on top of 15e2da656f41af0124f7577858536f3b65462ad5. now it also returns exact Ids which were not found which will be debugging simple.
* | | | Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2017-08-081-1/+1
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It should be sorted to be deterministic executed result. ``` % bundle exec rake test_postgresql --verbose TESTOPTS="--seed=52812" (snip) Failure: HasManyThroughAssociationsTest#test_has_many_association_through_a_has_many_association_to_self [/Users/kamipo/src/github.com/rails/rails/activerecord/test/cases/associations/has_many_through_associations_test.rb:820]: --- expected +++ actual @@ -1 +1 @@ -[#<Person id: 85, primary_contact_id: 84, gender: "M", number1_fan_id: 1, lock_version: 0, comments: nil, followers_count: 0, friends_too_count: 0, best_friend_id: nil, best_friend_of_id: nil, insures: 0, born_at: nil, created_at: "2017-08-08 07:33:52", updated_at: "2017-08-08 07:33:52", first_name: "John">, #<Person id: 1, primary_contact_id: 2, gender: "M", number1_fan_id: 3, lock_version: 0, comments: nil, followers_count: 1, friends_too_count: 1, best_friend_id: nil, best_friend_of_id: nil, insures: 0, born_at: nil, created_at: "2017-08-08 07:33:49", updated_at: "2017-08-08 07:33:49", first_name: "Michael">, #<Person id: 3, primary_contact_id: 2, gender: "F", number1_fan_id: 1, lock_version: 0, comments: nil, followers_count: 1, friends_too_count: 1, best_friend_id: nil, best_friend_of_id: nil, insures: 0, born_at: nil, created_at: "2017-08-08 07:33:49", updated_at: "2017-08-08 07:33:49", first_name: "Susan">] +#<ActiveRecord::Associations::CollectionProxy [#<Person id: 1, primary_contact_id: 2, gender: "M", number1_fan_id: 3, lock_version: 0, comments: nil, followers_count: 1, friends_too_count: 1, best_friend_id: nil, best_friend_of_id: nil, insures: 0, born_at: nil, created_at: "2017-08-08 07:33:49", updated_at: "2017-08-08 07:33:49", first_name: "Michael">, #<Person id: 3, primary_contact_id: 2, gender: "F", number1_fan_id: 1, lock_version: 0, comments: nil, followers_count: 1, friends_too_count: 1, best_friend_id: nil, best_friend_of_id: nil, insures: 0, born_at: nil, created_at: "2017-08-08 07:33:49", updated_at: "2017-08-08 07:33:49", first_name: "Susan">, #<Person id: 85, primary_contact_id: 84, gender: "M", number1_fan_id: 1, lock_version: 0, comments: nil, followers_count: 0, friends_too_count: 0, best_friend_id: nil, best_friend_of_id: nil, insures: 0, born_at: nil, created_at: "2017-08-08 07:33:52", updated_at: "2017-08-08 07:33:52", first_name: "John">]> ```
* | | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| | |
* | | Add a test case for overwriting existing condition on associationsRyuta Kamizono2017-07-071-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | Overwriting existing condition on associations has already supported (23bcc65 for eager loading, 2bfa2c0 for preloading). Fixes #27724. Closes #29154.
* | | 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
| | |
* | | ActiveRecord: do not create "has many through" records that have been removedTobias Kraze2017-06-281-0/+11
| | | | | | | | | | | | | | | If a record was built on a HasManyThroughAssociation, then removed, and then the record was saved, the removed record would be created anyways.
* | | Make helper methods in tests to privateRyuta Kamizono2017-05-191-18/+19
| | | | | | | | | | | | | | | `make_model` and `make_no_pk_hm_t` in `HasManyThroughAssociationsTest` are not a test case. it should be private.
* | | Add `Style/EmptyLinesAroundMethodBody` in `.rubocop.yml` and remove extra ↵Ryuta Kamizono2017-02-121-1/+0
| | | | | | | | | | | | empty lines
* | | Chain scope constraints should respect own table aliasRyuta Kamizono2017-02-011-0/+14
| | | | | | | | | | | | Fixes #27666.
* | | Raise error when has_many through is defined before through associationChris Holmes2017-01-041-0/+8
| | | | | | | | | | | | | | | | | | | | | https://github.com/rails/rails/issues/26834 This change raises an error if a has_many through association is defined before the through association.
* | | Remove deprecated force reload argument in association readersRafael Mendonça França2016-12-291-6/+0
| | |
* | | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-3/+3
| | |
* | | Resolve association class correctly when assigning ids on a through associationMatthew Draper2016-12-091-0/+7
| | |
* | | Add test for collection *_ids= setter when association primary key setDominic Cleal2016-11-241-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | Fixes casting of IDs to the data type of the association primary key, rather than then the data type of the model's primary key. (Tests use a string primary key on the association, rather than an int.) Tests issue #20995
* | | Restore RecordNotFound when *_ids= can't find records by IDDominic Cleal2016-11-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 9c9fb19 changed the behaviour of the _ids= setters for associations to raise an AssociationTypeMismatch when unknown IDs are given: Class: <ActiveRecord::AssociationTypeMismatch> Message: <"Developer(#43811860) expected, got NilClass(#16732720)"> This restores the original ActiveRecord::RecordNotFound exception with a much clearer error message: Class: <ActiveRecord::RecordNotFound> Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)"> Fixes #25719
* | | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-5/+5
| | |
* | | improve error message when include assertions failMichael Grosser2016-09-161-24/+24
| | | | | | | | | | | | | | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* | | Add three new rubocop rulesRafael Mendonça França2016-08-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | | modernizes hash syntax in activerecordXavier Noria2016-08-061-76/+76
| | |
* | | applies new string literal convention in activerecord/testXavier Noria2016-08-061-117/+117
| | | | | | | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | | Rename test methodMolchanov Andrey2016-05-121-1/+1
| |/ |/|
* | 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 #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
* | | 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
* | | Removed mocha from Active Record Part 1Ronak Jangir2015-08-251-5/+7
| | |
* | | Skip statement cache on through association readerRafael Mendonça França2015-08-121-0/+28
| |/ |/| | | | | | | | | | | If the through class has default scopes we should skip the statement cache. Closes #20745.
* | Silence deprecation warning from force reloadPrem Sichanugrist2015-07-161-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | We deprecate the support for passing an argument to force reload in 6eae366d0d2e5d5211eeaf955f56bd1dc6836758. That led to several deprecation warning when running Active Record test suite. This commit silence the warnings by properly calling `#reload` on the association proxy or on the association object instead. However, there are several places that `ActiveSupport::Deprecation.silence` are used as those tests actually tests the force reload functionality and will be removed once `master` is targeted next minor release (5.1).
* | Deprecate force association reload by passing truePrem Sichanugrist2015-07-151-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to simplify the association API, as you can call `reload` on the association proxy or the parent object to get the same result. For collection association, you can call `#reload` on association proxy to force a reload: @user.posts.reload # Instead of @user.posts(true) For singular association, you can call `#reload` on the parent object to clear its association cache then call the association method: @user.reload.profile # Instead of @user.profile(true) Passing a truthy argument to force association to reload will be removed in Rails 5.1.
* | Correct through associations using scopesSean Griffin2015-06-301-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The changes introduced to through associations in c80487eb were quite interesting. Changing `relation.merge!(scope)` to `relation = relation.merge(scope)` should in theory never cause any changes in behavior. The subtle breakage led to a surprising conclusion. The old code wasn't doing anything! Since `merge!` calls `instance_exec` when given a proc, and most scopes will look something like `has_many :foos, -> { where(foo: :bar) }`, if we're not capturing the return value, it's a no-op. However, removing the `merge` causes `unscope` to break. While we're merging in the rest of the chain elsewhere, we were never merging in `unscope` values, causing a breakage on associations where a default scope was being unscoped in an association scope (yuk!). This is subtly related to #20722, since it appears we were previously relying on this mutability. Fixes #20721. Fixes #20727.