aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* Don't rely on the column for type casting reflectionsSean Griffin2014-06-181-2/+2
|
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* early return on delete and destroy methodseileencodes2014-05-181-0/+2
| | | | | | When delete or destroy is called on all records nothing is deleted or destroyed. Intead of running through the code and still not deleteing anything, we should early return
* rename delete_all_records to delete_or_nullify_all_recordseileencodes2014-05-131-1/+1
| | | | | | | Rename delete_all_records because this name better describes what the method is doing. We can then remove :all from the hm:t version and pull out the unoptimized call to load_target in delete_records and pass it directly.
* begin refactoring delete_records methodeileencodes2014-05-131-1/+1
| | | | | | | | | | | | | | Refactor by creating two methods delete_all_records and delete_records to be called by delete_all and delete (or destroy) respectively. This reduces the number of conditionals required to handle _how_ records get deleted. The new delete_count method handles how scope is applied to which delete action. A delete_all_records method also has to be called in has_many_through association because of how the methods are chained. This will be refactored later on.
* refactor and clean up delete_all methodeileencodes2014-05-051-9/+1
| | | | | | | | Now that delete_all with destroy or delete_all dependency behave the same we no longer need this conditional. This means we can remove the new delete_all_with_dependency method I added and go straight to delete_records from delete_all, passing :all and the dependent directly.
* flip conditional in delete_all to handle nullify bettereileencodes2014-04-281-3/+3
| | | | | | | | Nullify (or nil dependency) was doing the same thing delete_all was doing in issue #14546, creating a large IN statement if the association was loaded. Loaded and not loaded associations should behave the same. The IN statement is also not great because it's inefficient.
* simplify the delete all w/ dependency methodeileencodes2014-04-281-3/+3
| | | | | | | After reviewing this code I realized the conditional that was there previously was basically saying if the dependency is not delete all. This is a better, cleaner, and clearer way to write this method.
* remove unnecessary code from delete methodeileencodes2014-04-281-10/+2
| | | | | Now that we have a new method delete_all_with_dependency this coupled conditional is no longer needed.
* write a new method to be accessed from delete_alleileencodes2014-04-281-1/+9
| | | | | | The delete method is very coupled with delete all even though only a portion of the conditionals apply. Decoupling this will make the code easier to understand and manipulate.
* use statement cache for belongs_to relationsAaron Patterson2014-04-221-1/+1
|
* cache scope building on associationsAaron Patterson2014-04-141-1/+15
| | | | SQL statements for querying associations are now cached
* remove check for present? from delete_alleileencodes2014-04-071-2/+2
| | | | | Passing in a blank string is a bug so there's no reason to check for a blank string.
* Merge pull request #11650 from prathamesh-sonpatki/renameRafael Mendonça França2014-04-041-4/+4
|\ | | | | | | Renamed private methods _create_record and _update_record
| * [Active Record] Renamed private methods create_record and update_recordPrathamesh Sonpatki2014-02-201-4/+4
| | | | | | | | | | | | This is to ensure that they are not accidentally called by the app code. They are renamed to _create_record and _update_record respectively. Closes #11645
* | fix delete_all to remove records directlyeileencodes2014-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When delete_all is run on a CollectionProxy and has a dependency of delete_all the SQL that is produced has an IN statement. (DELETE FROM `associated_model` where `associated_model` .`parent_id` = 1 AND `associated_model`.`id` IN (1, 2, 3...)). This only happens if the association is not loaded (both loaded and non-loaded delete_all should behave the same. This is a huge problem when it comes to deleting many records because the query becomes very slow. Instead the SQL produced should be (DELETE FROM `assoicated_model` where `associated_model`.`parent_model_id`=1). I fixed this by making sure the check for loaded and destroy also makes sure that the dependent is not delete_all, so the conditional goes to the else and deletes the records directly without the IN statement.
* | Avoid duplicated conditionalsCarlos Antonio da Silva2014-03-141-2/+1
| |
* | passing an ActiveRecord object to `exists?` is deprecated.Aaron Patterson2014-03-131-1/+1
| | | | | | | | | | Pass the id of the object to the method by calling `.id` on the AR object.
* | Remove unnecessary db call when replacing.Arthur Neves2014-02-281-1/+3
| | | | | | | | | | | | | | When replacing a has_many association with the same one, there is no need to do a round-trip to the db to create/and drop a new transaction. [fixes #14220]
* | let `insert_record` actuall save the object.Aaron Patterson2014-02-251-2/+2
| | | | | | | | | | | | | | | | | | | | `before_add` callbacks are fired before the record is saved on `has_and_belongs_to_many` assocations *and* on `has_many :through` associations. Before this change, `before_add` callbacks would be fired before the record was saved on `has_and_belongs_to_many` associations, but *not* on `has_many :through` associations. Fixes #14144
* | Revert "speed up the collection proxy reader method, but slow down the ↵Arthur Neves2014-02-201-5/+1
|/ | | | | | | | constructor" This reverts commit f9e4c3c7c0c4152b62fe9202a9d12262884bb118. [fixes #14116]
* speed up the collection proxy reader method, but slow down the constructorAaron Patterson2014-02-131-1/+5
|
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-5/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* Merge pull request #10134 from ↵Rafael Mendonça França2014-01-031-2/+2
|\ | | | | | | | | derikson/collection_proxy_select_with_multiple_args Change CollectionProxy#select to take the same arguments as ActiveRecord::select
| * Changed ActiveRecord::Associations::CollectionProxy#select to take multiple ↵Dan Erikson2013-04-081-2/+2
| | | | | | | | | | | | arguments. This makes the arguments the same as ActiveRecord::QueryMethods::select.
* | Merge pull request #13417 from TalkativeTree/comments_changeRichard Schneeman2013-12-191-1/+1
|\ \ | | | | | | fix CollectionAssociation's comments
| * | change CollectionAssociation's comments to say Association instead of ↵Ben Angel2013-12-191-1/+1
| | | | | | | | | | | | AssociationProxy to match changes for 3.1 removing Association proxy.
* | | Mark the arguments needed by activerecord-deprecated_finders with a TODORafael Mendonça França2013-12-111-0/+2
| | |
* | | Revert "Merge pull request #12518 from vipulnsward/remove_count_options"Rafael Mendonça França2013-12-111-1/+3
|/ / | | | | | | | | | | | | It is needed for activerecord-depecated_finders This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
* | Fix wrong behavior where associations with dependent: :destroy optionsRafael Mendonça França2013-11-011-4/+2
| | | | | | | | | | | | | | | | | | was using nullify strategy This caused a regression in applications trying to upgrade. Also if the user set the dependent option as destroy he expects to get the records removed from the database.
* | `Relation#count` doesn't use options anymore.Vipul A M2013-10-131-3/+1
| |
* | remove HABTM associationsAaron Patterson2013-10-021-1/+0
| |
* | fix .find when inverse is setArthur Neves2013-09-251-5/+4
| | | | | | | | .find([1]) should return an Array of entries, even when a invese object is in memory already
* | Merge pull request #10500 from kennyj/fix_10450Rafael Mendonça França2013-09-221-3/+3
|\ \ | | | | | | | | | | | | | | | | | | Fixed a bug in when using has_many association with :inverse_of option and UUID primary key. Conflicts: activerecord/CHANGELOG.md
| * | Fixed a bug in when using has_many association with :inverse_of option and ↵kennyj2013-05-081-3/+3
| |/ | | | | | | UUID primary key.
* | Merge pull request #12137 from lann/fix_association_first_lastRafael Mendonça França2013-09-121-3/+1
|\ \ | | | | | | | | | | | | | | | | | | Make CollectionAssociation first/last with integer fetch with query Conflicts: activerecord/CHANGELOG.md
| * | Make CollectionAssociation first/last with integer fetch with queryLann Martin2013-09-091-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When first or last is called with an integer on an unloaded association, the entire collection is loaded. This differs surprisingly from the behavior of Relation#first/last, which translate the call into a limit query. For large collections this can make a big difference in performance. Change CollectionAssociation#fetch_first_or_last_using_find? to make this kind of call delegate to Relation.
* | | ask the association for records rather than calling `send`Aaron Patterson2013-09-101-1/+2
|/ /
* | Restore the use of `#add_to_target` for nested attribute updates on existing ↵Ben Woosley2013-08-121-4/+4
| | | | | | | | | | | | | | | | | | records, and don't bother updating the association if the update is going to be rejected anyway. This requires adding a `skip_callbacks` argument to `#add_to_target` so that we don't call the callbacks multiple times in this case, which is functionally an application of existing association data, rather than an addition of a new record to the association.
* | do is_a? tests on assignment so runtime is fasterAaron Patterson2013-07-311-8/+1
| |
* | callback should always have a valueAaron Patterson2013-07-311-1/+1
| |
* | no need to to_symAaron Patterson2013-07-311-1/+1
| |
* | add a specific factory method rather than using newAaron Patterson2013-07-231-1/+1
| |
* | fix indentationNeeraj Singh2013-07-021-14/+14
| |
* | Removed support for deprecated `finder_sql` in associations.Neeraj Singh2013-07-021-38/+5
| |
* | Removed support for deprecated `counter_sql`Neeraj Singh2013-07-021-15/+11
| |
* | Do not invoke callbacks when delete_all is calledNeeraj Singh2013-06-301-13/+29
| | | | | | | | | | | | | | | | | | | | | | 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)`
* | do not load all child records for inverse caseNeeraj Singh2013-06-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | currently `post.comments.find(Comment.first.id)` would load all comments for the given post to set the inverse association. This has a huge performance penalty. Because if post has 100k records and all these 100k records would be loaded in memory even though the comment id was supplied. Fix is to use in-memory records only if loaded? is true. Otherwise load the records using full sql. Fixes #10509
* | Revert "Merge pull request #10566 from neerajdotname/10509d"Jon Leighton2013-06-191-1/+1
| | | | | | | | | | | | | | | | | | | | This reverts commit 2b817a5e89ac0e7aeb894a40ae7151a0cf3cef16, reversing changes made to 353a398bee68c5ea99d76ac7601de0a5fef6f4a5. Conflicts: activerecord/CHANGELOG.md Reason: the build broke
* | do not load all child records for inverse caseNeeraj Singh2013-06-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | currently `post.comments.find(Comment.first.id)` would load all comments for the given post to set the inverse association. This has a huge performance penalty. Because if post has 100k records and all these 100k records would be loaded in memory even though the comment id was supplied. Fix is to use in-memory records only if loaded? is true. Otherwise load the records using full sql. Fixes #10509