aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* use ruby 1.8 Hash syntax [ci skip]Yves Senn2013-03-221-1/+1
|
* do not reset associations when preloading twice.Yves Senn2013-03-221-0/+7
| | | | | | | | Closes #9806. As the `through_options` always contained `{:order=>nil}` the second time, the preloader ran, the association was always reset. This patch only adds the `:order` to the `through_options` if it is set.
* Fix issue #7526. Reload the target if it's stale.larrylv2013-03-051-0/+14
| | | | | | | | * This has been fixed at master via `365b8b6`, but not at 3-2-stable branch. * @stale_state should be nil when a model isn't saved. via `0f3901e`. * set @stale_state to nil when reset the target.
* Use order to get the first record since postgresql returns in theRafael Mendonça França2013-02-201-1/+1
| | | | desired order
* keep the build :green_heart:, #first on 1.8.7 and pg is differentYves Senn2013-02-191-1/+1
| | | | | | | | | | | The build only failed for ruby-1.8.7 and pg. The problem was that the statement: ```ruby author = Author.includes(:comments_with_order_and_conditions, :posts).first ``` resulted in Author with ID 2 where on all other rubies / db-engines Author with ID 1 was retunred. Of course this breaks the assertions.
* don't cache invalid subsets when preloading hmt associations.Yves Senn2013-02-191-0/+6
| | | | | | | | | | | | | Backport #9252. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/eager_test.rb The preloader code on 3-2-stable is not based on relations but on option hashes. I had to modify the original patch and comparing the option hashes could be more fuzzy than comparing the relations. All the tests passed though.
* Revert "Merge pull request #9252 from senny/8423_hmt_preloading_bug"Rafael Mendonça França2013-02-151-6/+0
| | | | | | | This reverts commit c5451777b038c5e48567f69256986ae42a2cde48. Conflicts: activerecord/CHANGELOG.md
* Merge pull request #9252 from senny/8423_hmt_preloading_bugRafael Mendonça França2013-02-141-0/+6
| | | | | | | don't cache invalid subsets when preloading hmt associations Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/eager_test.rb
* backport of fix for issue #7630Matthew Robertson2013-02-131-0/+11
|
* Revert "Merge pull request #7983 from georgebrock/bug7950-squashed"Carlos Antonio da Silva2013-01-151-7/+0
| | | | | | | | | | | This reverts commit 88a296dccc401da143d90cad54b693ff06bf2b58, reversing changes made to 666a7e34f553cef4c8878362eafc79c7e3f310c3. Conflicts: activerecord/CHANGELOG.md Reason: this has been resulting in some hard to track bugs and is introducing a possible breackage in a stable version.
* Revert "Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmt"Ernie Miller2013-01-111-5/+0
| | | | | | | This reverts commit ee439895759b38431ad025f3c234831f30dadcdb. It would appear that #7661 had unintended consequences to the API. Until we can sort those out, this should not be in 3.2.x, and wait for 4.0.0.
* Remove not used variable in eager testCarlos Antonio da Silva2013-01-071-1/+0
|
* Fix undefined method `to_i' introduced since 3.2.8Jason Stirk2013-01-041-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a bug introduced in 96a13fc7 which breaks behaviour of integer fields in 3.2.8. In 3.2.8, setting the value of an integer field to a non-integer (eg. Array, Hash, etc.) would default to 1 (true) : # 3.2.8 p = Post.new p.category_id = [ 1, 2 ] p.category_id # => 1 p.category_id = { 3 => 4 } p.category_id # => 1 In 3.2.9 and above, this will raise a NoMethodError : # 3.2.9 p = Post.new p.category_id = [ 1, 2 ] NoMethodError: undefined method `to_i' for [1, 2]:Array Whilst at first blush this appear to be sensible, it combines in bad ways with scoping. For example, it is common to use scopes to control access to data : @collection = Posts.where(:category_id => [ 1, 2 ]) @new_post = @collection.new In 3.2.8, this would work as expected, creating a new Post object (albeit with @new_post.category_id = 1). However, in 3.2.9 this will cause the NoMethodError to be raised as above. It is difficult to avoid triggering this error without descoping before calling .new, breaking any apps running on 3.2.8 that rely on this behaviour. This patch deviates from 3.2.8 in that it does not retain the somewhat spurious behaviour of setting the attribute to 1. Instead, it explicitly sets these invalid values to nil : p = Post.new p.category_id = [ 1, 2 ] p.category_id # => nil This also fixes the situation where a scope using an array will "pollute" any newly instantiated records. @new_post = @collection.new @new_post.category_id # => nil Finally, 3.2.8 exhibited a behaviour where setting an object to an integer field caused it to be coerced to "1". This has not been retained, as it is spurious and surprising in the same way that setting Arrays and Heshes was : c = Category.find(6) p = Post.new # 3.2.8 p.category_id = c p.category_id # => 1 # This patch p.category_id = c p.category_id # => nil This commit includes explicit test cases that expose the original issue with calling new on a scope that uses an Array. As this is a common situation, an explicit test case is the best way to prevent regressions in the future. It also updates and separates existing tests to be explicit about the situation that is being tested (eg. AR objects vs. other objects vs. non-integers)
* backport #8403, no intermediate AR objects when eager loading.Yves Senn2012-12-041-0/+6
| | | | | | | | | Closes #3313 Conflicts: activerecord/CHANGELOG.md activerecord/test/models/developer.rb
* backport #8291, prevent mass assignment of polymorphic type with `build`Yves Senn2012-11-221-0/+8
| | | | | | | | | Closes #8265 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/association.rb
* Merge pull request #7983 from georgebrock/bug7950-squashedCarlos Antonio da Silva2012-11-161-0/+7
|\ | | | | | | | | | | | | | | Backport 4bc2ae0 to fix #7950 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/calculations.rb
| * Test/changelog for has_many bug on unsaved recordsGeorge Brocklehurst2012-11-101-0/+7
| | | | | | | | | | | | | | See issue #7950. The previous commit fixes this bug, and is a backport of 4bc2ae0da1dd812aee759f6d13ad428354cd0e13.
* | Merge pull request #8154 from bogdan/has_one_association_performanceCarlos Antonio da Silva2012-11-121-0/+6
|/ | | | | | | Remove unwanted transaction when has one association is built Conflicts: activerecord/CHANGELOG.md
* Ensure calling first/last with options correctly set inverse associationCarlos Antonio da Silva2012-11-011-0/+8
| | | | Also related to #8087. Thanks @al2o3cr.
* Fix issue with collection associations and first(n)/last(n)Carlos Antonio da Silva2012-11-011-0/+12
| | | | | | | | | | | | | | | | | When calling first(n) or last(n) in a collection, Active Record was improperly trying to set the inverse of instance in case that option existed. This change was introduced by fdf4eae506fa9895e831f569bed3c4aa6a999a22. In such cases we don't need to do that "manually", since the way collection will be loaded will already handle that, so we just skip setting the inverse association when any argument is given to first(n)/last(n). The test included ensures that these scenarios will have the inverse of instance set properly. Fixes #8087, Closes #8094.
* Fix has_many assocation w/select load after createErnie Miller2012-10-121-0/+8
| | | | | | | | | | If you create a new record via a collection association proxy that has not loaded its target, and which selects additional attributes through the association, then when the proxy loads its target, it will inadvertently trigger a deprecation notice during attribute writing when CollectionAssociation#merge_target_lists attempts to do its thing, since the newly loaded records will possess attributes the created record does not.
* Merge pull request #6978 from frodsan/count_nosql_unsaved_parentRafael Mendonça França2012-10-043-0/+18
| | | | Count returns 0 without querying if parent is not saved
* Revert "backport fair connection pool 02b2335563 to 3-2-stable"Rafael Mendonça França2012-09-202-8/+0
| | | | | | | | | | | | | This reverts commit 0693e079708a52b777f2b7872b8e3d467b880a0d. Revert "Cache columns metadata to avoid extra while testing" This reverts commit a82f1e3f5d11c8dfba9f4c911745ec40a7965216. Reason: This is causing failures in the postgresql build. See http://travis-ci.org/#!/rails/rails/builds/2485584 Related with #7675
* Cache columns metadata to avoid extra while testingRafael Mendonça França2012-09-182-0/+8
|
* Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmtRafael Mendonça França2012-09-171-0/+5
| | | | Fix collection= on hm:t join models when unsaved
* Merge pull request #7666 from ↵Rafael Mendonça França2012-09-171-1/+1
| | | | | | kennyj/fix_9fa3f102813eeeec440abd75870dfa7b23835665 Fix warning: method redefine. Testcase name are duplicated.
* Merge pull request #7651 from steveklabnik/issue_3956Rafael Mendonça França2012-09-161-1/+31
| | | | | | | | | Don't preserve SELECT columns on COUNT Closes #7651 Conflicts: activerecord/test/cases/associations/has_many_associations_test.rb
* ConnectionAdapters::Column.type_cast_code should always convert values to ↵Thiago Pradi2012-09-091-0/+6
| | | | integer calling #to_i
* Ensure association preloading properly merges default scope and association ↵Pratik Naik2012-08-281-0/+12
| | | | | | | | conditions Conflicts: activerecord/test/models/reader.rb
* Merge pull request #7377 from ↵Carlos Antonio da Silva2012-08-211-0/+6
| | | | | | | | | | | brainopia/use_inversed_parent_for_first_and_last_child Use inversed parent for first and last child of has_many association [Backport] Closes #3223. Conflicts: activerecord/lib/active_record/associations/collection_association.rb
* Merge pull request #7286 from kennyj/fix_7191Rafael Mendonça França2012-08-101-0/+13
| | | | | | Fix #7191. Remove unnecessary transaction when assigning has_one associations. Conflicts: activerecord/test/cases/associations/has_one_associations_test.rb
* Revert "Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-012-40/+9
| | | | | | | | | | This reverts commit a79bfa92e7bdc31b346d13ee5447d3fdac382bfb. Conflicts: activerecord/CHANGELOG.md We shouldn't introducing deprecations in point releases. It will be deprecated in 4.0 instead.
* Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-202-9/+40
|
* Make test cover previous reversionJon Leighton2012-06-071-0/+1
|
* Revert "Perf: Don't load the association for #delete_all."Jon Leighton2012-06-071-12/+0
| | | | | | | | | | This reverts commit b98d1e21635d8776de8893cc09bd86c71f6c78f0. Closes #6609 Conflicts: activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
* Restore behavior of Active Record 3.2.3 scopesAndrew White2012-06-011-24/+0
| | | | | | | | | | | | | | A series of commits relating to preloading and scopes caused a regression. Cloning the relation calls initialize_copy which resets a number of instance variables to nil. Without this the scope thinks that it is already loaded when it is called again. Reverts the following commits: 13f1401a6cf0266a3b0a91b173f976db2d4e50f3 8491740ca5361ba9df20e1c8b906c709f5bfbc12 dffbb521a0d00c8673a3ad6e0e8ff526f32daf4e Fixes #6575, #6576 & #6577
* Ensure that CollectionAssociation#replace returns proper targetPiotr Sarnacki2012-05-191-2/+2
| | | | | | | | The fix commited in e2a070c was returning the `new_target`, as a try to return whatever user replaced association with. The problem is, the resulting association target may be ordered differently. In such case we want to return the target that will be later used for that association.
* fix #delete_all with habtm with :delete_sqlJon Leighton2012-05-181-0/+6
|
* Perf: Don't load the association for #delete_all.Jon Leighton2012-05-181-0/+12
| | | | | | | | Bug #6289 Conflicts: activerecord/test/cases/associations/has_many_associations_test.rb
* Fix CollectionAssociation#replace to return new target (closes #6231)Piotr Sarnacki2012-05-161-0/+12
| | | | | | Conflicts: activerecord/test/cases/associations/has_many_associations_test.rb
* Add extra order clause to fix failing test on Ruby 1.8.7Carlos Antonio da Silva2012-04-241-1/+1
|
* Adds test to check that circular preloading does not modify Model.unscoped ↵Benedikt Deicke2012-04-191-0/+24
| | | | | | | | (as described in #5667) Conflicts: activerecord/test/cases/associations/eager_test.rb
* Revert "Fix #5667. Preloading should ignore scoping."Jeremy Kemper2012-04-181-11/+0
| | | | | | | | Causes a subtle regression where record.reload includes the default scope. Hard to reproduce in isolation. Seems like the relation is getting infected by some previous usage. This reverts commit dffbb521a0d00c8673a3ad6e0e8ff526f32daf4e.
* Fix #5667. Preloading should ignore scoping.Jon Leighton2012-03-301-0/+11
| | | | | | Conflicts: activerecord/test/cases/associations/eager_test.rb
* Change the order argument from ('id') to ('taggings.id')Yasuo Honda2012-03-281-1/+1
| | | | to address ORA-00918 error
* Add order to tests that rely on db ordering, to fix failing tests on pgCarlos Antonio da Silva2012-03-223-17/+16
| | | | | | | Also skip persistente tests related to UPDATE + ORDER BY for postgresql PostgreSQL does not support updates with order by, and these tests are failing randomly depending on the fixture loading order now.
* Not need to pass join attributes to association buildRafael Mendonça França2012-03-081-3/+2
|
* Add test case to has_many through association when mass_assignment_sanitizer isRafael Mendonça França2012-03-081-4/+21
| | | | | | | | :strict Conflicts: activerecord/test/models/person.rb
* Add tests to test that through associations are not readonly, and we can ↵kuahyeow2012-03-081-0/+11
| | | | update the records we retrive from the association
* Fix #5069 - Protect foreign key from mass assignment throught association ↵Jean Boussier2012-03-052-0/+38
| | | | builder