aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Move set_inverse_instance to association.build_recordArthur Neves2013-09-302-1/+1
| | | | [fixes #10371]
* fix inverse_of when find_or_initialize_by_*Arthur Neves2013-09-261-4/+6
| | | | | inverse_of relation was not being set when calling find_or_initialize_by_ and the entry was found on the db.
* Merge pull request #12359 from arthurnn/inverse_on_callbacksRafael Mendonça França2013-09-251-0/+1
| | | | | | | Make sure inverse_of is visible on the has_many callbacks Conflicts: activerecord/CHANGELOG.md activerecord/test/models/company.rb
* Revert "Revert "Merge pull request #10901 from ↵Yves Senn2013-06-251-1/+1
| | | | | | | | armstrjare/fix_query_null_foreign_key_on_new_record_collection_ids_reader"" This reverts commit 5009b078875e596a2fba7827336f7548aa6e35ac. Also updated the CHANGELOG and adjusted the test-case to match the one on master.
* Revert "Merge pull request #10901 from ↵Yves Senn2013-06-221-1/+1
| | | | | | | | | armstrjare/fix_query_null_foreign_key_on_new_record_collection_ids_reader" This reverts commit 6675d713186c270de1c4684bc1e56742ea2e19e1, reversing changes made to 919d1a19d5e7871d50c1531351fc3f736bad5d07. I missed to check the target branch and wrongly merged it into 3-2-stable directly.
* Fixes CollectionAssociation#ids_reader returning incorrect ids for new recordsJared Armstrong2013-06-211-1/+1
|
* It's scoped in 3-2-stable!Arun Agrawal2013-05-241-1/+1
| | | scope => scoped
* Merge pull request #10713 from senny/10693_fix_primary_key_option_on_has_manyRafael Mendonça França2013-05-231-2/+1
| | | | | | | Fix the `:primary_key` option for `has_many` associations. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/has_many_association.rb
* Preserve context for joins while merging relationsAndrew Horner2013-05-112-2/+7
| | | | | | This is a backport of #10164, already merged into master. The issue is described in lengthy detail in issues #3002 and #5494.
* Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroyRafael Mendonça França2013-05-061-1/+4
| | | | | | | | | | | Confirm a record has not already been destroyed before decrementing counter cache Conflicts: activerecord/CHANGELOG.md Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/builder/belongs_to.rb
* do not reset associations when preloading twice.Yves Senn2013-03-221-2/+1
| | | | | | | | 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.
* @target might be nil when Identity Map is enabled.Larry Lv2013-03-081-3/+8
| | | | | | | * With Identity Map enabled, NameError might be raised and @target is nil. So we should always ensure `@target ||= find_target`. * Only force reload target when it is stale.
* Fix issue #7526. Reload the target if it's stale.larrylv2013-03-054-6/+8
| | | | | | | | * 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.
* don't cache invalid subsets when preloading hmt associations.Yves Senn2013-02-191-1/+2
| | | | | | | | | | | | | 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-2/+1
| | | | | | | This reverts commit c5451777b038c5e48567f69256986ae42a2cde48. Conflicts: activerecord/CHANGELOG.md
* Merge pull request #9252 from senny/8423_hmt_preloading_bugRafael Mendonça França2013-02-141-1/+2
| | | | | | | 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/+5
|
* Revert "Merge pull request #7983 from georgebrock/bug7950-squashed"Carlos Antonio da Silva2013-01-151-15/+1
| | | | | | | | | | | 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-14/+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.
* backport #8291, prevent mass assignment of polymorphic type with `build`Yves Senn2012-11-221-1/+2
| | | | | | | | | 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-1/+15
|\ | | | | | | | | | | | | | | Backport 4bc2ae0 to fix #7950 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/calculations.rb
| * use bind values for join columnsAaron Patterson2012-11-101-1/+16
| | | | | | | | | | | | | | | | | | | | This is a backport of 4bc2ae0da1dd812aee759f6d13ad428354cd0e13. It fixes bug #7950. Conflicts: activerecord/lib/active_record/relation/calculations.rb activerecord/lib/active_record/relation/finder_methods.rb
* | Merge pull request #8154 from bogdan/has_one_association_performanceCarlos Antonio da Silva2012-11-121-1/+9
|/ | | | | | | 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-1/+3
| | | | Also related to #8087. Thanks @al2o3cr.
* Fix issue with collection associations and first(n)/last(n)Carlos Antonio da Silva2012-11-011-1/+1
| | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | 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.
* Eager autoload Preloader classesJohn Firebaugh2012-10-101-10/+14
| | | | | | Without eager autoloading, these would be autoloaded only when #preloader_for is called, which is too late in threaded applications.
* Merge pull request #6978 from frodsan/count_nosql_unsaved_parentRafael Mendonça França2012-10-041-0/+2
| | | | Count returns 0 without querying if parent is not saved
* Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmtRafael Mendonça França2012-09-171-0/+14
| | | | Fix collection= on hm:t join models when unsaved
* Merge pull request #7651 from steveklabnik/issue_3956Rafael Mendonça França2012-09-161-1/+1
| | | | | | | | | Don't preserve SELECT columns on COUNT Closes #7651 Conflicts: activerecord/test/cases/associations/has_many_associations_test.rb
* Ensure association preloading properly merges default scope and association ↵Pratik Naik2012-08-281-3/+1
| | | | | | | | conditions Conflicts: activerecord/test/models/reader.rb
* Merge pull request #7377 from ↵Carlos Antonio da Silva2012-08-211-1/+1
| | | | | | | | | | | 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
* Do not use update_column where update_attribute is not interchangeableRafael Mendonça França2012-08-151-1/+1
| | | | | | | | | | | | Revert "Deprecate update_attribute." This reverts commit b081f6b59fb3f15d12043072ad9b331ffd2bc56e. Reason: Since the new deprecation policy we removed the deprecation of update_attribute but we didn't reverted the changes to use update_column. Fixes #7306
* Merge pull request #7286 from kennyj/fix_7191Rafael Mendonça França2012-08-101-13/+15
| | | | | | 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-21/+0
| | | | | | | | | | 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-0/+21
|
* Deprecate update_attribute.Steve Klabnik2012-06-141-1/+1
| | | | | | | | | | | Historically, update_attribute and update_attributes are similar, but with one big difference: update_attribute does not run validations. These two methods are really easy to confuse given their similar names. Therefore, update_attribute is being deprecated in favor of update_column, and will be removed in Rails 4. See the discussion on rails-core here: https://groups.google.com/d/topic/rubyonrails-core/BWPUTK7WvYA/discussion
* Revert "Perf: Don't load the association for #delete_all."Jon Leighton2012-06-074-33/+9
| | | | | | | | | | 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-3/+2
| | | | | | | | | | | | | | 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
* predicate builder should not recurse for determining where columns.Aaron Patterson2012-05-301-1/+16
| | | | | | Thanks to Ben Murphy for reporting this CVE-2012-2661
* Ensure that CollectionAssociation#replace returns proper targetPiotr Sarnacki2012-05-191-1/+1
| | | | | | | | 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 HABTM syntax error in Ruby 1.8.xErnie Miller2012-05-181-2/+2
|
* fix #delete_all with habtm with :delete_sqlJon Leighton2012-05-181-0/+1
|
* Perf: Don't load the association for #delete_all.Jon Leighton2012-05-184-9/+33
| | | | | | | | 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/+2
| | | | | | Conflicts: activerecord/test/cases/associations/has_many_associations_test.rb
* Revert "Revert "Fix #5667. Preloading should ignore scoping.""Benedikt Deicke2012-04-191-2/+3
| | | | | | | | This reverts commit 1166d49f62ccab789be208112163ad13183224e2. Conflicts: activerecord/test/cases/associations/eager_test.rb
* Revert "Fix #5667. Preloading should ignore scoping."Jeremy Kemper2012-04-181-3/+2
| | | | | | | | 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-2/+3
| | | | | | Conflicts: activerecord/test/cases/associations/eager_test.rb
* Not need to pass join attributes to association buildRafael Mendonça França2012-03-082-4/+10
|
* Fix #5069 - Protect foreign key from mass assignment throught association ↵Jean Boussier2012-03-051-1/+2
| | | | builder