aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/belongs_to_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix counter_cache double increment bugTom Kadwill2016-04-281-0/+1
|
* Make #increment! and #decrement! methods concurency safeBogdan Gusiev2015-10-051-27/+19
|
* raise ActiveModel::MissingAttributeError when trying to access a ↵Diego Carrion2015-06-161-1/+1
| | | | | | | | relationship without the foreign key attribute fixes regression reported on #20253 ActiveRecord::Base#[] was not used cause of 8b95420
* Improve consistency of counter caches updating in memorySean Griffin2015-01-261-0/+3
| | | | | | | | | | | | | | | | | When we made sure that the counter gets updated in memory, we only did it on the has many side. The has many side only does the update if the belongs to cannot. The belongs to side was updated to update the counter cache (if it is able). This means that we need to check if the belongs_to is able to update in memory on the has_many side. We also found an inconsistency where the reflection names were used to grab the association which should update the counter cache. Since reflection names are now strings, this means it was using a different instance than the one which would have the inverse instance set. Fixes #18689 [Sean Griffin & anthonynavarre]
* Improve the performance of reading belongs_to associationsSean Griffin2014-12-221-5/+6
| | | | | | | | | | | | `ActiveRecord::Base#[]` has overhead that was introduced in 4.2. The `foo["id"]` working with PKs other than ID isn't really a case that we want to support publicly, but deprecating was painful enough that we avoid it. `_read_attribute` was introduced as the faster alternative for use internally. By using that, we can save a lot of overhead. We also save some overhead by reading the attribute one fewer times in `stale_state`. Fixes #18151
* add has_one? method and reuse instead of checking macroeileencodes2014-06-091-1/+1
| | | | | | Instead of checking for `macro == :has_one` throughout the codebase we can create a `has_one?` method to match the `belongs_to?`, `polymorphic?` and other methods.
* Hide BelongsToAssociation#increment_counters and #decrement_countersJean Boussier2014-04-151-2/+2
|
* Use inheritance chain instead of callbacks to increment counter caches after ↵Jean Boussier2014-04-141-4/+14
| | | | create
* extract cache counter logic to one methodAaron Patterson2013-12-121-11/+10
|
* remove duplicate codeAaron Patterson2013-12-121-15/+6
|
* extract a method for updating without a record objectAaron Patterson2013-12-121-6/+10
|
* extract methods out of the cache update methodAaron Patterson2013-12-121-14/+22
|
* pull a nil check up one frameAaron Patterson2013-12-121-6/+10
|
* remove more nil checksAaron Patterson2013-12-121-6/+5
|
* remove nil checkAaron Patterson2013-12-121-6/+10
| | | | | calling replace_keys could possibly do a nil check twice, this commit reduces it to once.
* remove the nil check from set_inverse_instanceAaron Patterson2013-12-121-1/+1
| | | | | methods that call set_inverse_instance with a record will not have to pay the cost of a nil check on every call
* Remove useless comment and white spaces :scissors: [ci skip]Carlos Antonio da Silva2013-09-011-2/+2
|
* Adding a bang to method name of raise_on_type_mismatch.wangjohn2013-03-211-1/+1
|
* BELONGS TO ASSOCIATION | Typo fixlibin2013-02-251-1/+1
|
* improved different_target conditionsAngelo Capilleri2013-01-081-2/+5
|
* move dependency logic out of generated methodsJon Leighton2012-08-101-0/+5
|
* @stale_state should be nil when a model isn't saved.kennyj2012-04-131-1/+1
|
* Some refactor for association.kennyj2012-04-121-0/+5
| | | | | | | * Remove unused association_class method. * Remove a unnecessary assignment. * Move @updated to BelongsToAssociation that only reference this instance variable. * Reset @stale_state at the reset method. I think this place is right place.
* Fix belongs_to polymorphic with custom primary key on target.Jon Leighton2011-09-261-1/+5
| | | | Closes #3104.
* Don't find belongs_to target when the foreign_key is NULL. Fixes #2828Georg Friedrich2011-09-051-0/+4
|
* Fix exception if old and new targets are both nil. Fixes #1471.Jon Leighton2011-07-121-1/+1
|
* Rename target_klass to klassJon Leighton2011-02-211-1/+1
|
* Delegate Association#options to the reflection, and replace ↵Jon Leighton2011-02-211-1/+1
| | | | 'reflection.options' with 'options'. Also add through_options and source_options methods for through associations.
* Singular associations no longer use a proxy, so no need to check for the ↵Jon Leighton2011-02-211-1/+1
| | | | proxy type on assignment.
* Associations - where possible, call attributes methods rather than directly ↵Jon Leighton2011-02-211-10/+10
| | | | accessing the instance variables
* Let's be less blasé about method visibility on association proxiesJon Leighton2011-01-301-0/+1
|
* find_target can also go into SingularAssociationJon Leighton2011-01-161-4/+0
|
* Abstract a bit more into SingularAssociationJon Leighton2011-01-161-2/+1
|
* Use self.target= rather than @target= as the former automatically sets loadedJon Leighton2011-01-161-3/+1
|
* Abstract common code from BelongsToAssociation and HasOneAssociation into ↵Jon Leighton2011-01-161-19/+1
| | | | SingularAssociation
* belongs_to records should be initialized within the association scopeJon Leighton2011-01-161-2/+8
|
* Add create_association! for belongs_toJon Leighton2011-01-161-0/+4
|
* reduce funcalls by using falsey objectsAaron Patterson2011-01-141-2/+2
|
* Construct an actual ActiveRecord::Relation object for the association scope, ↵Jon Leighton2011-01-071-17/+0
| | | | rather than a hash which is passed to apply_finder_options. This allows more flexibility in how the scope is created, for example because scope.where(a, b) and scope.where(a).where(b) mean different things.
* When preloading a belongs_to, the target should still be set (to nil) if ↵Jon Leighton2011-01-031-3/+1
| | | | there is no foreign key present. And the loaded flag should be set on the association proxy. This then allows us to remove the foreign_key_present? check from BelongsToAssociation#find_target. Also added a test for the same thing on polymorphic associations.
* Create the association scope directly rather than going through with_scopeJon Leighton2011-01-031-1/+1
|
* Rename AssociationProxy#foreign_key_present to foreign_key_present?Jon Leighton2011-01-031-3/+3
|
* Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-11/+4
| | | | | | | | | | state:resolved] This required changing the code to keep the association proxy for a belongs_to around, despite its target being nil. Which in turn required various changes to the way that stale target checking is handled, in order to support various edge cases (loaded target is nil then foreign key added, foreign key is changed and then changed back, etc). A side effect is that the code is nicer and more succinct. Note that I am removing test_no_unexpected_aliasing since that is basically checking that the proxy for a belongs_to *does* change, which is the exact opposite of the intention of this commit. Also adding various tests for various edge cases and related things. Phew, long commit message!
* Rename AssociationReflection#primary_key_name to foreign_key, since the ↵Jon Leighton2010-12-311-7/+7
| | | | options key which it relates to is :foreign_key
* Support for :counter_cache on polymorphic belongs_toJon Leighton2010-12-311-1/+1
|
* Refactor BelongsToAssociation to allow BelongsToPolymorphicAssociation to ↵Jon Leighton2010-12-311-49/+55
| | | | inherit from it
* Refactor we_can_set_the_inverse_on_this? to use a less bizarre name amongst ↵Jon Leighton2010-12-261-4/+5
| | | | other things
* If a has_many goes :through a belongs_to, and the foreign key of the ↵Jon Leighton2010-12-231-1/+4
| | | | belongs_to changes, then the has_many should be considered stale.
* Improved strategy for updating a belongs_to association when the foreign key ↵Jon Leighton2010-12-231-0/+8
| | | | changes. Rather than resetting each affected association when the foreign key changes, we should lazily check for 'staleness' (where fk does not match target id) when the association is accessed.
* removing space errorAaron Patterson2010-11-221-1/+1
|