aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* 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
* fix associations when using per class databasesLars Kanis2012-03-043-8/+5
| | | | | | would get ConnectionNotEstablished error because it always tried to use ActiveRecord::Base's connection, even though it should be using the connection of the model whose context we're operating in
* Merge pull request #4543 from jdelStrother/find_or_initJon Leighton2012-02-011-2/+1
| | | | Don't instantiate two objects in collection proxy / find_or_instantiate_by
* Merge pull request #4783 from gregolsen/ids_reader_fixJon Leighton2012-01-311-1/+1
| | | | ids_reader method fixed, test added to has_many association (for PostgreSQL)
* added failing tests for has_many, has_one and belongs_to associations with ↵Jakub Kuźma2011-12-211-6/+1
| | | | | | strict mass assignment sanitizer, fixed build_record to not merge creation_attributes, removed failing nested attributes tests (that feature was broken anyway) #4051 Signed-off-by: José Valim <jose.valim@gmail.com>
* bypass preloading for ids_readerSergey Nartimov2011-12-181-2/+10
| | | | | when fetching ids for a collection, bypass preloading to avoid the unnecessary performance overhead
* Allow nested attributes in associations to update values in it's owner ↵Andrew Kaspick2011-12-141-0/+2
| | | | object. Fixes a regression from 3.0.x
* Fix #3672 again (dependent: delete_all perf)Jon Leighton2011-12-146-9/+26
|
* Fix #3890. (Calling proxy_association in scope chain.)Jon Leighton2011-12-081-2/+8
|
* reintroduce patch from #726 to handle nested eager loading via associationsJay Levitt2011-11-301-1/+1
|
* ActiveRecord::Relation#pluck methodBogdan Gusiev2011-11-301-1/+1
|
* Merge pull request #3636 from joshsusser/masterJon Leighton2011-11-296-21/+22
|\ | | | | association methods are now generated in modules
| * avoid warningsJosh Susser2011-11-276-15/+15
| | | | | | | | | | | | | | This change uses Module.redefine_method as defined in ActiveSupport. Making Module.define_method public would be as clean in the code, and would also emit warnings when redefining an association. That is pretty messy given current tests, so I'm leaving it for someone else to decide what approach is better.
| * use GeneratedFeatureMethods module for associationsJosh Susser2011-11-272-7/+13
| |
| * association methods are now generated in modulesJosh Susser2011-11-157-30/+25
| | | | | | | | | | | | | | | | | | | | Instead of generating association methods directly in the model class, they are generated in an anonymous module which is then included in the model class. There is one such module for each association. The only subtlety is that the generated_attributes_methods module (from ActiveModel) must be forced to be included before association methods are created so that attribute methods will not shadow association methods.
* | load has_many associations keyed off a custom primary key if that key is ↵Brian Samson2011-11-252-1/+5
| | | | | | | | present but the record is unsaved
* | Perf fixJon Leighton2011-11-191-2/+6
|/ | | | | | | If we're deleting all records in an association, don't add a IN(..) clause to the query. Fixes #3672.
* Use uniq instead of manually putting a DISTINCT in the queryJon Leighton2011-11-051-14/+2
|
* Merge pull request #3507 from jmazzi/issue-3503Jeremy Kemper2011-11-031-2/+6
| | | | Preserve SELECT columns on the COUNT for finder_sql when possible
* Memoize through associationJon Leighton2011-11-031-8/+11
|
* Remove all revelant through records.Jon Leighton2011-11-031-9/+9
| | | | | | | | | If a record is removed from a has_many :through, all of the join records relating to that record should also be removed from the through association's target. (Previously the records were removed in the database, but only one was removed from the in-memory target array.)
* Fix adding multiple instances of the same record to a has_many :through.Jon Leighton2011-11-031-21/+43
| | | | Fixes #3425.
* Fix #3247.Jon Leighton2011-11-031-1/+1
| | | | | Fixes creating records in a through association with a polymorphic source type.
* Merge pull request #3030 from htanata/fix_habtm_select_query_methodJon Leighton2011-09-261-4/+0
| | | | Fix: habtm doesn't respect select query method