aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Dropped deprecated option `:restrict` for `:dependent` in associationsNeeraj Singh2013-07-035-11/+4
|
* Removed support for deprecated `delete_sql` in associations.Neeraj Singh2013-07-032-16/+11
|
* Removed support for deprecated `insert_sql` in associations.Neeraj Singh2013-07-022-10/+6
|
* fix indentationNeeraj Singh2013-07-021-14/+14
|
* Removed support for deprecated `finder_sql` in associations.Neeraj Singh2013-07-023-41/+6
|
* Removed support for deprecated `counter_sql`Neeraj Singh2013-07-024-18/+14
|
* Merge pull request #10604 from ↵Rafael Mendonça França2013-07-012-15/+31
|\ | | | | | | | | | | | | | | | | neerajdotname/delete_all_should_not_call_callbacks Do not invoke callbacks when delete_all is called Conflicts: activerecord/CHANGELOG.md
| * Do not invoke callbacks when delete_all is calledNeeraj Singh2013-06-302-15/+31
| | | | | | | | | | | | | | | | | | | | | | 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)`
* | Removed deprecated options for assocationsNeeraj Singh2013-07-022-19/+0
| | | | | | | | | | Deprecated options `delete_sql`, `insert_sql`, `finder_sql` and `counter_sql` have been deleted.
* | Removed deprecated method scopedNeeraj Singh2013-07-011-5/+0
| |
* | don't shadow `through_scope` method name with local var.Yves Senn2013-06-301-7/+7
|/
* Simplify/fix implementation of default scopesJon Leighton2013-06-284-9/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* Apply default scope when joining associations.Jon Leighton2013-06-281-0/+2
| | | | | | | | | | | | | | | | | | | For example: class Post < ActiveRecord::Base default_scope -> { where published: true } end class Comment belongs_to :post end When calling `Comment.join(:post)`, we expect to receive only comments on published posts, since that is the default scope for posts. Before this change, the default scope from `Post` was not applied, so we'd get comments on unpublished posts.
* 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
* `CollectionProxy#include?` returns `true` and `false` as documented.Yves Senn2013-06-181-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-06-141-3/+4
|\ | | | | | | | | Conflicts: guides/source/upgrading_ruby_on_rails.md
| * enhanced comments for foreign_key_present? methodNeeraj Singh2013-05-231-3/+4
| |
* | bind values should not be merged between scopesAaron Patterson2013-06-111-1/+1
| |
* | stop adding a new method for touch callbacksAaron Patterson2013-06-111-29/+21
| |
* | push the touch method outside the evalAaron Patterson2013-06-111-13/+34
| |
* | remove unused variableAaron Patterson2013-06-111-1/+0
| |
* | check whether the association is constructible rather than checking constantsAaron Patterson2013-06-111-3/+3
| |
* | use attribute methods for finding key values rather than generating method namesAaron Patterson2013-06-111-3/+3
| |
* | push belongs_to counter cache method to a single methodAaron Patterson2013-06-111-17/+18
| |
* | push before_destroy counter cache method to a single methodAaron Patterson2013-06-111-12/+17
| |
* | remove evaled belongs_to counter cache methodAaron Patterson2013-06-111-8/+22
| |
* | adding callbacks should be privateAaron Patterson2013-06-111-4/+6
| |
* | remove evals from the associationAaron Patterson2013-06-111-8/+2
| |
* | reduce evals in depdendent associationsAaron Patterson2013-06-111-1/+2
| |
* | Getting rid of the +automatic_inverse_of: false+ option in associations in favorwangjohn2013-06-082-2/+2
| | | | | | | | | | of using +inverse_of: false+ option. Changing the documentation and adding a CHANGELOG entry for the automatic inverse detection feature.
* | Fix the `:primary_key` option for `has_many` associations.Yves Senn2013-05-231-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When removing records from a `has_many` association it used the `primary_key` defined on the association. Our test suite didn't fail because on all occurences of `:primary_key`, the specified column was available in both tables. This prevented the code from raising an exception but it still behaved badly. I added a test-case to prevent regressions that failed with: ``` 1) Error: HasManyAssociationsTest#test_has_many_assignment_with_custom_primary_key: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: essays.first_name: UPDATE "essays" SET "writer_id" = NULL WHERE "essays"."writer_id" = ? AND "essays"."first_name" IS NULL ```
* | just set the default argument, a nil parent should be an errorAaron Patterson2013-05-211-2/+1
| |
* | fold the collection rather than multiple assigmentsAaron Patterson2013-05-211-3/+2
| |
* | use drop rather than calculate the array lengthAaron Patterson2013-05-211-1/+1
|/
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-05-195-7/+34
|\
| * copy edits[ci skip]Vijay Dev2013-05-191-11/+8
| |
| * Added some more documentation for define_readers and define_writer of the ↵aditya-kapoor2013-05-153-0/+15
| | | | | | | | Association and its inherited classes
| * Added some more documentation for ↵aditya-kapoor2013-05-151-0/+11
| | | | | | | | ActiveRecord::Associations::Builder::Association class
| * Added documentation for ActiveRecord::Associations::Builder::Association classaditya-kapoor2013-05-151-0/+4
| |
| * emphasize that callbacks are called in destroy_allNeeraj Singh2013-05-132-7/+7
| | | | | | | | | | | | | | Cleaned up rdoc a bit emphasizing that callbacks are called. Also removed the stress on the fact that records are always removed. If callbacks return false then records will not be deleted.
* | stop doing assingments in an iteratorAaron Patterson2013-05-171-2/+6
|/
* Extract JoinDependency#join_relation to DRY the repeated application of the ↵Ben Woosley2013-05-101-0/+7
| | | | #join_associations.
* Move #proxy_association method to AssociationRelationJon Leighton2013-05-101-3/+1
|
* Set the inverse when association queries are refinedJon Leighton2013-05-101-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | Suppose Man has_many interests, and inverse_of is used. Man.first.interests.first.man will correctly execute two queries, avoiding the need for a third query when Interest#man is called. This is because CollectionAssociation#first calls set_inverse_instance. However Man.first.interests.where("1=1").first.man will execute three queries, even though this is obviously a subset of the records in the association. This is because calling where("1=1") spawns a new Relation object from the CollectionProxy object, and the Relation has no knowledge of the association, so it cannot set the inverse instance. This commit solves the problem by making relations spawned from CollectionProxies return a new Relation subclass called AssociationRelation, which does know about associations. Records loaded from this class will get the inverse instance set properly. Fixes #5717. Live commit from La Conf! :sparkles:
* Created a method to automatically find inverse associations and cachewangjohn2013-05-072-2/+2
| | | | | | the results. Added tests to check to make sure that inverse associations are automatically found when has_many, has_one, or belongs_to associations are defined.
* Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroyRafael Mendonça França2013-05-061-1/+3
|\ | | | | | | | | | | | | Confirm a record has not already been destroyed before decrementing counter cache Conflicts: activerecord/CHANGELOG.md
| * Confirm a record has not already been destroyed before decrementingBen Tucker2013-05-061-1/+3
| | | | | | | | | | | | | | | | | | counter cache At present, calling destroy multiple times on the same record results in the belongs_to counter cache being decremented multiple times. With this change the record is checked for whether it is already destroyed prior to decrementing the counter cache.
* | Do not overwrite manually built records during one-to-one nested attribute ↵Olek Janiszewski2013-05-031-4/+8
|/ | | | | | | | | | | | | | | | | | | | | assignment For one-to-one nested associations, if you build the new (in-memory) child object yourself before assignment, then the NestedAttributes module will not overwrite it, e.g.: class Member < ActiveRecord::Base has_one :avatar accepts_nested_attributes_for :avatar def avatar super || build_avatar(width: 200) end end member = Member.new member.avatar_attributes = {icon: 'sad'} member.avatar.width # => 200