aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_one_through_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* Don't expose `SingularAssociation#replace` which is internal APIRyuta Kamizono2018-05-161-5/+5
| | | | | Originally `SingularAssociation#replace` abstract method is private, and doesn't intend to be called directly.
* Fix .new with multiple through associationsSam DeCesare2018-04-091-1/+5
| | | | | | | | | | | | | | | | | | | This fixes a bug with building an object that has multiple `has_many :through` associations through the same object. Previously, when building the object via .new, the intermediate object would be created instead of just being built. Here's an example: Given a GameBoard, that has_one Owner and Collection through Game. The following line would cause a game object to be created in the database. GameBoard.new(owner: some_owner, collection: some_collection) Whereas, if passing only one of those associations into `.new` would cause the Game object to be built and not created in the database. Now the above code will only build the Game object, and not save it.
* Fix building has_one through recordRyuta Kamizono2018-01-231-6/+5
| | | | Fixes #31762.
* Fix broken doc for Active Record [ci skip]Yoshiyuki Hirano2017-08-251-1/+1
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Reload `through_record` that has been destroyed in `create_through_record`Ryuta Kamizono2017-01-291-0/+4
| | | | | | | | | | | | | | This is an alternative of #27714. If `has_one :through` association has set `nil`, `through_record` is destroyed but still remain loaded target in `through_proxy` until `reload` or `reset` explicitly. If `through_proxy` is not reset (remain destroyed (frozen) target), setting new record causes `RuntimeError: Can't modify frozen hash`. To prevent `RuntimeError`, should reload `through_record` that has been destroyed in `create_through_record`.
* `load_target` is a public methodRyuta Kamizono2016-07-231-1/+1
| | | | `send` is unnecessary.
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-1/+1
|
* Merge branch 'master' into nested_has_many_throughJon Leighton2011-03-041-26/+20
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/class_methods/join_dependency.rb activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb activerecord/lib/active_record/associations/has_many_association.rb activerecord/lib/active_record/associations/has_many_through_association.rb activerecord/lib/active_record/associations/has_one_association.rb activerecord/lib/active_record/associations/has_one_through_association.rb activerecord/lib/active_record/associations/through_association_scope.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/associations/has_many_through_associations_test.rb activerecord/test/cases/associations/has_one_through_associations_test.rb activerecord/test/cases/reflection_test.rb activerecord/test/cases/relations_test.rb activerecord/test/fixtures/memberships.yml activerecord/test/models/categorization.rb activerecord/test/models/category.rb activerecord/test/models/member.rb activerecord/test/models/reference.rb activerecord/test/models/tagging.rb
| * Delegate through_reflection and source_reflection to reflectionJon Leighton2011-02-211-1/+1
| |
| * Associations - where possible, call attributes methods rather than directly ↵Jon Leighton2011-02-211-2/+2
| | | | | | | | accessing the instance variables
| * Split AssociationProxy into an Association class (and subclasses) which ↵Jon Leighton2011-02-181-1/+1
| | | | | | | | manages the association, and a CollectionProxy class which is *only* a proxy. Singular associations no longer have a proxy. See CHANGELOG for more.
| * Add :nodoc: to ThroughAssociation and HasOneAssociationJon Leighton2011-02-181-1/+1
| |
| * Indent methods under private/protected sectionsJon Leighton2011-01-301-14/+14
| |
| * Rename some variablesJon Leighton2011-01-161-11/+11
| |
| * Use self.target= in HasOneThroughAssociation tooJon Leighton2011-01-161-4/+3
| |
| * We can use the association_proxy method directly in HasOneThroughAssociation nowJon Leighton2011-01-111-3/+2
| |
| * find_target can be inheritedJon Leighton2011-01-111-4/+0
| |
| * Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-1/+1
| | | | | | | | | | | | | | | | | | | | 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!
| * Add a HasAssociation module for common code for has_* associationsJon Leighton2010-12-261-3/+1
| |
| * Remove pointless use of 'private'Jon Leighton2010-12-261-1/+0
| |
| * Use the through association proxy for operations on the through record, so ↵Jon Leighton2010-12-261-11/+13
| | | | | | | | that those operations are automatically scoped and therefore construct_join_attributes does not need to use construct_owner_attributes.
| * If a has_many goes :through a belongs_to, and the foreign key of the ↵Jon Leighton2010-12-231-0/+1
| | | | | | | | belongs_to changes, then the has_many should be considered stale.
| * Respect the default_scope on a join model when reading a through associationJon Leighton2010-12-161-1/+1
| |
* | Merge branch 'master' into nested_has_many_throughJon Leighton2010-12-121-1/+1
|\| | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/associations/class_methods/join_dependency.rb activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb activerecord/lib/active_record/associations/has_many_through_association.rb
| * Partialy revert f1c13b0dd7b22b5f6289ca1a09f1d7a8c7c8584bJosé Valim2010-11-281-1/+1
| |
* | Merge branch 'master' into nested_has_many_throughJon Leighton2010-11-171-1/+1
|\| | | | | | | | | | | Conflicts: activerecord/lib/active_record/associations/has_many_through_association.rb activerecord/test/cases/associations/has_many_through_associations_test.rb
| * use persisted? instead of new_record? wherever possibleDavid Chelimsky2010-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | - persisted? is the API defined in ActiveModel - makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord [#5927 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
| * Refactoring: replace the mix of variables like @finder_sql, @counter_sql, ↵Jon Leighton2010-10-301-1/+1
| | | | | | | | etc with just a single scope hash (created on initialization of the proxy). This is now used consistently across all associations. Therefore, all you have to do to ensure finding/counting etc is done correctly is implement the scope correctly.
* | Fix naughty trailing whitespaceJon Leighton2010-10-311-1/+1
| |
* | Refactoring: replace the mix of variables like @finder_sql, @counter_sql, ↵Jon Leighton2010-10-171-1/+1
| | | | | | | | etc with just a single scope hash (created on initialization of the proxy). This is now used consistently across all associations. Therefore, all you have to do to ensure finding/counting etc is done correctly is implement the scope correctly.
* | Make sure nested through associations are read onlyJon Leighton2010-10-151-0/+2
|/
* Adds title to activerecord/lib/active_record/associations/*Rizwan Reza2010-06-161-0/+1
|
* Allow ho:through#build when the owner is a new record [#1749 state:resolved]Tristan Dunn2009-08-101-3/+9
| | | | Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* HasOneThroughAssociation still shouldn't derive from HasManyThroughAssociation.Adam Milligan2009-06-121-10/+12
| | | | | | [#1642 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* has_one :through should not create a new association when assigned nil [#698 ↵Daniel Guettler2009-05-171-8/+8
| | | | | | state:resolved] Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* fix assignment to has_one :through associations.Matt Jones2008-11-151-4/+3
| | | | Signed-off-by: Michael Koziarski <michael@koziarski.com>
* Fix two has_one :through errorspivotal2008-08-271-0/+4
| | | | | | | | * Set the association target on assignment; * Reset target to nil on reset, rather than empty array. Signed-off-by: Michael Koziarski <michael@koziarski.com> [#895 state:committed]
* Remove duplicate code from associations. [Pratik]Pratik Naik2008-04-061-1/+1
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9231 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Add has_one :through support, finally. Closes #4756 [thechrisoshow]Rick Olson2008-03-211-0/+28
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9067 5ecf4fe2-1ee6-0310-87b1-e25e094e27de