aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/belongs_to.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix counter_cache double increment bugTom Kadwill2016-04-281-0/+2
|
* Define `:foreign_type` as a valid option in `SingularAssociation`yui-knk2016-01-191-1/+1
| | | | | `:foreign_type` is a valid option for `belongs_to` and `has_one` so remove this to `SingularAssociation`.
* Make sure we touch all the parents when touch_later.Arthur Neves2015-12-061-2/+1
| | | | | | | | | | | | | | | | | | | | The problem was that when saving an object, we would call touch_later on the parent which wont be saved immediteally, and it wont call any callbacks. That was working one level up because we were calling touch, during the touch_later commit phase. However that still didnt solve the problem when you have a 3+ levels of parents to be touched, as calling touch would affect the parent, but it would be too late to run callbacks on its grand-parent. The solution for this, is instead, call touch_later upwards when the first touch_later is called. So we make sure all the timestamps are updated without relying on callbacks. This also removed the hard dependency BelongsTo builder had with the TouchLater module. So we can still have the old behaviour if TouchLater module is not included. [fixes 5f5e6d924973003c105feb711cefdb726f312768] [related #19324]
* Update belongs_to.rbEhsan Yousefi2015-11-081-2/+1
| | | There is no need to to assign reflection name to a variable, because it's called once.
* docs, add missing `:nodoc: for `Associations::Builder`. [ci skip]Yves Senn2015-10-131-1/+1
| | | | | | This class is only used internally. We should keep it out of public documentation. This patch adds nodoc for `ActiveRecord::Associations::Builder` and everything nested within.
* Fix counter_cache for polymorphic associationsStefan Kanev2015-07-191-4/+12
| | | | | | | | | | | | | | Also removes a false positive test that depends on the fixed bug: At this time, counter_cache does not work with polymorphic relationships (which is a bug). The test was added to make sure that no StaleObjectError is raised when the car is destroyed. No such error is currently raised because the lock version is not incremented by appending a wheel to the car. Furthermore, `assert_difference` succeeds because `car.wheels.count` does not check the counter cache, but the collection size. The test will fail if it is replaced with `car.wheels_count || 0`.
* Batch touch parent recordsArthur Neves2015-04-081-6/+7
| | | | | | | | | | [fixes #18606] Make belongs_to use touch over touch_later when running the callbacks. Add more tests and small method rename Thanks Jeremy for the feedback.
* Require `belongs_to` by default.Josef Šimánek2015-02-211-1/+19
| | | | Deprecate `required` option in favor of `optional` for belongs_to.
* Remove support to activerecord-deprecated_findersRafael Mendonça França2015-01-021-4/+2
|
* Merge pull request #12450 from iantropov/masterRafael Mendonça França2014-06-271-0/+5
|\ | | | | | | | | | | | | | | | | Fix bug, when ':dependent => :destroy' violates foreign key constraints Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/builder/association.rb activerecord/lib/active_record/associations/builder/has_one.rb
| * Fix bug, when ':dependent => :destroy' option violates foreign key ↵Ivan Antropov2013-10-261-0/+4
| | | | | | | | constraints, issue #12380
* | Prevented belongs_to: touch propagating up if there are no changes being savedBrock Trappitt2014-05-211-1/+1
| |
* | Hide BelongsToAssociation#increment_counters and #decrement_countersJean Boussier2014-04-151-1/+0
| |
* | Use inheritance chain instead of callbacks to increment counter caches after ↵Jean Boussier2014-04-141-16/+0
| | | | | | | | destroy
* | Use inheritance chain instead of callbacks to increment counter caches after ↵Jean Boussier2014-04-141-12/+1
| | | | | | | | create
* | Make counter cache decrementation on destroy idempotentJean Boussier2014-04-131-4/+5
| |
* | On destroying do not touch destroyed belongs to association.Paul Nikitochkin2013-12-231-1/+1
| | | | | | | | Fixes: #13445
* | Revert the whole refactoring in the association builder classes.Rafael Mendonça França2013-12-111-2/+4
| | | | | | | | This is to get activerecord-deprecated_finders work again
* | Bring back the valid_options class accessorRafael Mendonça França2013-12-111-1/+1
| | | | | | | | It is need in activerecord-deprecated_finders
* | polymorphic belongs_to association with touch: true updates old record correctlySeverin Schoepke2013-12-051-1/+7
| | | | | | | | | | | | | | | | | | Example: Given you have a comments model with a polymorphic commentable association (e.g. books and songs) with the touch option set. Every time you update a comment its commentable should be touched. This was working when you changed attributes on the comment or when you moved the comment from one book to another. However, it was not working when moving a comment from a book to a song. This is now fixed.
* | Raise `ArgumentError` when `has_one` is used with `counter_cache`Godfrey Chan2013-11-291-1/+1
| | | | | | | | | | | | | | | | | | Previously, the `has_one` macro incorrectly accepts the `counter_cache` option due to a bug, although that options was never supported nor functional on `has_one` and `has_one ... through` relationships. It now correctly raises an `ArgumentError` when passed that option. For reference, this bug was introduced in 52f8e4b9.
* | Method visibility will not make difference hereRafael Mendonça França2013-10-091-2/+0
| |
* | Move macro to class levelRafael Mendonça França2013-10-091-1/+1
| |
* | Make valid_options a class methodRafael Mendonça França2013-10-091-1/+1
| |
* | Push define_accessors to class level since we don't need anythig fromRafael Mendonça França2013-10-081-2/+2
| | | | | | | | the instance
* | Move add_counter_cache_methods to class levelRafael Mendonça França2013-10-081-2/+2
| |
* | we can define callbacks without a builder instanceAaron Patterson2013-10-021-3/+3
| |
* | push methods that don't depend on the instance to the classAaron Patterson2013-10-021-4/+4
| |
* | decouple belongs_to callback definition from the builder instance.Aaron Patterson2013-10-021-4/+4
| | | | | | | | All the information is on the reflection, so just get it there.
* | valid_options doesn't depend on the instance, so push it to the classAaron Patterson2013-10-021-1/+1
| |
* | association builder is no longer needed for counter cache, so remove itAaron Patterson2013-10-021-7/+6
| |
* | push constructable? on to the reflectionAaron Patterson2013-10-021-6/+2
| |
* | name is on the reflection, so just use the reflectionAaron Patterson2013-10-021-2/+2
|/
* remove dependency on @model when defining callbacksAaron Patterson2013-08-011-5/+5
|
* extract more mutations to the callerAaron Patterson2013-08-011-7/+6
|
* separate some mutations from reflection constructionAaron Patterson2013-08-011-1/+5
|
* #11288: Removed duplicated touchingPaul Nikitochkin2013-07-051-1/+1
| | | | | | if belongs to model with touch option on touch Closes #11288
* 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
|
* 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.
* Lookup the class at runtime, not when the association is builtAndrew White2013-04-241-2/+2
| | | | | | | | | Trying to lookup the parent class when the association is being built runs the risk of generating uninitialized constant errors because classes haven't been fully defined yet. To work around this we look up the class at runtime through the `association` method. Fixes #10197.
* Revert "Revert "`belongs_to :touch` behavior now touches old association ↵Andrew White2013-04-241-1/+12
| | | | | | | | | when transitioning to new association" until a proper fix is found for #10197" This reverts commit 7389df139a35436f00876c96d20e81ba23c93f0a. Conflicts: activerecord/test/cases/timestamp_test.rb
* Revert "`belongs_to :touch` behavior now touches old association when ↵David Heinemeier Hansson2013-04-231-12/+1
| | | | transitioning to new association" until a proper fix is found for #10197