aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* deprecate `Relation#uniq` use `Relation#distinct` instead.Yves Senn2015-05-261-1/+1
| | | | | | | | | See #9683 for the reasons we switched to `distinct`. Here is the discussion that triggered the actual deprecation #20198. `uniq`, `uniq!` and `uniq_value` are still around. They will be removed in the next minor release after Rails 5.
* remove duplicate test.Yves Senn2015-05-081-10/+2
| | | | | | | | | The old `test_create_bang_returns_falsy_when_join_record_has_errors` had a missleading name and was a duplicate of `test_save_should_not_raise_exception_when_join_record_has_errors`. Since it had an assertion on the return value I renamed it accordingly and got rid of the duplicate test.
* Rename association option :class to :anonymous_classAndrew White2015-04-211-8/+8
| | | | | | | | | | | | | In 1f006c an option was added called :class to allow passing anonymous classes to association definitions. Since using :class instead of :class_name is a fairly common typo even amongst experienced developers this can result in hard to debug errors arising in raise_on_type_mismatch? To fix this we're renaming the option from :class to :anonymous_class as that is a more correct description of what the option is for. Since this was an internal, undocumented option there is no need for a deprecation. Fixes #19659
* Properly create through records when called with `where`Sean Griffin2015-02-261-0/+6
| | | | | | | | | | | Various behaviors needed by associations (such as creating the through record) are lost when `where` is called, since we stop having a `CollectionProxy` and start having an `AssociationRelation` which does not contain this behavior. I *think* we should be able to rm `AssociationRelation`, but we have tests saying the changes required to do that would be bad (Without saying why. Of course. >_>) Fixes #19073.
* Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-1/+10
|\ | | | | | | | | | | | | | | Add setting of FK for throgh associations while building Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Add setting of FK for throgh associations while buildingIvan Antropov2014-05-251-1/+10
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
| |
* | Fix a bug where AR::RecordNotSaved loses error messagesYuki Nishijima2014-11-271-2/+5
| | | | | | | | | | | | Since 3e30c5d, it started ignoring the given error message. This commit changes the behavior of AR::RecordNotSaved#initialize so that it no longer loses the given error message.
* | Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | | | | | | `Computer` class needs to be require See #17217 for more details
* | Do not mark object as persisted after an association is savedRafael Mendonça França2014-09-051-19/+0
| | | | | | | | | | | | | | | | | | | | | | Callback order in Active Record objects are important. Users should not define callbacks before the association definition or surprising behaviours like the described at #3798 will happen. This callback order dependency is documented at https://github.com/rails/rails/blob/31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1/activerecord/lib/active_record/associations.rb#L1222-1227. This reverts #15728. Fixes #16620.
* | Ignore SCHEMA queries when asserting no queriesAkira Matsuda2014-08-281-1/+1
| |
* | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-5/+5
| | | | | | | | | | | | | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* | Merge pull request #15728 from sgrif/sg-double-save-hm-tRafael Mendonça França2014-06-191-1/+20
|\ \ | | | | | | | | | | | | | | | | | | | | | Don't save through records twice Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * | Don't save through records twiceSean Griffin2014-06-171-0/+19
| | | | | | | | | | | | | | | | | | | | | If the through record gets created in an `after_create` hook that is defined before the association is defined (therefore after its `after_create` hook) get saved twice. This ensures that the through records are created only once, regardless of the order of the hooks.
* | | Don't include inheritance column in the through_scope_attributesNat Budin2014-06-171-0/+8
|/ /
* / Through associations should set both parent ids on join modelsSean Griffin2014-06-131-0/+13
|/ | | | | | | | | | | | | member = Member.new(club: Club.new) member.save! Before: member.current_membership.club_id # => nil After: member.current_membership.club_id # => club's id
* clear shouldnt fire callbacks so remove order testeileencodes2014-04-281-3/+0
| | | | | | Since clear shouldn't fire callbacks the order doesn't matter since it was never updated. Remove the portion of this test that tests for order after clear.
* Perfer to define methods instead of calling testRafael Mendonça França2014-04-221-4/+4
| | | | This file is using this pattern already
* Fix syntax errorRafael Mendonça França2014-04-221-0/+1
|
* Merge pull request #14573 from habermann24/has_many_through_fixRafael Mendonça França2014-04-221-0/+11
|\ | | | | | | | | | | | | | | Properly handle scoping with has_many :through. Fixes #14537. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Properly handle scoping with has_many :through. Fixes #14537.Jan Habermann2014-04-031-0/+12
| |
* | Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548Rafael Mendonça França2014-04-101-1/+13
|\ \ | |/ |/| | | | | | | | | Fix insertion of records for hmt association with scope Conflicts: activerecord/CHANGELOG.md
| * Fix insertion of records for hmt association with scope, fix #3548Ivan Antropov2013-11-171-1/+13
| |
* | Add regression test for collection proxy readerArthur Neves2014-02-201-0/+7
|/ | | | [related #14116]
* Prevent the counter cache from being decremented twicedm1try2013-11-111-0/+9
| | | | | when destroying a record on a has_many :through association. :destroy method has own counter_cache callbacks.
* Assert the return value in the testRafael Mendonça França2013-10-271-1/+1
|
* Skip `include_values` from through associations chains for building target scopePaul Nikitochkin2013-10-271-0/+4
| | | | Fixes: #12242, #9517, #10240
* Using flat_map instead of map and flattenArun Agrawal2013-10-091-1/+1
| | | | | | original commit 8998441967a8cfc6e4302c29664ab9d0acd77704 Reverted here ec8ef1e1055c4e1598da13f49d30261f07f4a9b4
* adding a test to demonstrate how to use STI subclasses on the far rightAaron Patterson2013-09-271-0/+7
| | | | side of a hm:t association along with preloading.
* push preloaded test up to the factory method so we can eliminateAaron Patterson2013-09-241-1/+0
| | | | conditionals from the individual preloaded classes
* we can't sort by lhs since the middle records have difference classesAaron Patterson2013-09-231-1/+2
| | | | and possibly different rules for finding those objects
* adding a test for sti on middle tables with sorting on RHSAaron Patterson2013-09-231-1/+14
|
* hm:t preloading will respect order set on the RHS associationAaron Patterson2013-09-231-0/+15
|
* fix deleting join models with no pkAaron Patterson2013-09-111-5/+47
|
* hm:t join tables may not have a primary keyAaron Patterson2013-09-061-0/+18
|
* adding a hm:t test for singleton ar objectsAaron Patterson2013-09-031-0/+27
|
* add missing fixtures fileAaron Patterson2013-08-301-1/+2
|
* make sure there are actually some categories when running the testAaron Patterson2013-08-291-0/+1
|
* pk should not be required for hm:t associationsAaron Patterson2013-08-291-0/+7
|
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2013-08-171-1/+1
|\ | | | | | | | | | | | | | | Conflicts: actionview/README.rdoc activerecord/lib/active_record/migration.rb guides/source/development_dependencies_install.md guides/source/getting_started.md
| * Revert "Merge branch 'master' of github.com:rails/docrails"Vijay Dev2013-08-171-1/+1
| | | | | | | | | | | | | | This reverts commit 70d6e16fbad75b89dd1798ed697e7732b8606fa3, reversing changes made to ea4db3bc078fb3093ecdddffdf4f2f4ff3e1e8f9. Seems to be a code merge done by mistake.
* | add a test for concat on hm:t associationsAaron Patterson2013-08-021-0/+7
|/
* used flat_map instead of map.flattenKarunakar (Ruby)2013-07-251-1/+1
|
* Make sure that a joins Relation can be merged with has_many :through + ↵Akira Matsuda2013-07-101-0/+6
| | | | | | association proxy Closes #11248.
* Do not invoke callbacks when delete_all is calledNeeraj Singh2013-06-301-0/+34
| | | | | | | | | | | Method `delete_all` should not be invoking callbacks and this feature was deprecated in Rails 4.0. This is being removed. `delete_all` will continue to honor the `:dependent` option. However if `:dependent` value is `:destroy` then the default deletion strategy for that collection will be applied. User can also force a deletion strategy by passing parameter to `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`
* has_many through obeys order on through associationNeeraj Singh2013-04-041-1/+7
| | | | fixes #10016
* Prevent Relation#merge from collapsing wheres on the RHSJon Leighton2013-01-271-0/+7
| | | | | | | | | | | | | | | | | | | | | | | This caused a bug with the new associations implementation, because now association conditions are represented as Arel nodes internally right up to when the whole thing gets turned to SQL. In Rails 3.2, association conditions get turned to raw SQL early on, which prevents Relation#merge from interfering. The current implementation was buggy when a default_scope existed on the target model, since we would basically end up doing: default_scope.merge(association_scope) If default_scope contained a where(foo: 'a') and association_scope contained a where(foo: 'b').where(foo: 'c') then the merger would see that the same column is representated on both sides of the merge and collapse the wheres to all but the last: where(foo: 'c') Now, the RHS of the merge is left alone. Fixes #8990