aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_one_association.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Construct an actual ActiveRecord::Relation object for the association scope, ↵Jon Leighton2011-01-071-11/+3
| | | | 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.
* Remove undocumented feature from has_one where you could pass false as the ↵Jon Leighton2011-01-031-20/+8
| | | | | | | | | | | | second parameter to build_assoc or create_assoc, and the existing associated object would be untouched (the foreign key would not be nullified, and it would not be deleted). If you want behaviour similar to this you can do the following things: * Use :dependent => :nullify (or don't specify :dependent) if you want to prevent the existing associated object from being deleted * Use has_many if you actually want multiple associated objects * Explicitly set the foreign key if, for some reason, you really need to have multiple objects associated with the same has_one. E.g. previous = obj.assoc obj.create_assoc previous.update_attributes(:obj_id => obj.id)
* Create the association scope directly rather than going through with_scopeJon Leighton2011-01-031-2/+2
|
* Use the association directly in other places tooJon Leighton2011-01-031-11/+9
|
* Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-3/+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!
* Rename AssociationReflection#primary_key_name to foreign_key, since the ↵Jon Leighton2010-12-311-3/+3
| | | | options key which it relates to is :foreign_key
* And owner_quoted_id can go tooJon Leighton2010-12-311-9/+0
|
* Refactor we_can_set_the_inverse_on_this? to use a less bizarre name amongst ↵Jon Leighton2010-12-261-8/+3
| | | | other things
* Add a HasAssociation module for common code for has_* associationsJon Leighton2010-12-261-0/+2
|
* Remove AssociationProxy#dependent? - it's badly named and only used in one placeJon Leighton2010-12-261-1/+1
|
* Associations: DRY up the code which is generating conditions, and make it ↵Jon Leighton2010-12-261-14/+3
| | | | all use arel rather than SQL strings
* using arel to compile sql statementsAaron Patterson2010-12-251-1/+2
|
* Partialy revert f1c13b0dd7b22b5f6289ca1a09f1d7a8c7c8584bJosé Valim2010-11-281-1/+1
|
* use persisted? instead of new_record? wherever possibleDavid Chelimsky2010-11-091-6/+6
| | | | | | | | | | | - 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-23/+16
| | | | 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.
* dry up the hash dup and avoid sending nil valuesAaron Patterson2010-08-111-7/+7
|
* Adds title to activerecord/lib/active_record/associations/*Rizwan Reza2010-06-161-0/+1
|
* Add more tests for the various ways we can assign objects to associations. ↵Murray Steele2009-12-281-2/+1
| | | | | | | | [#3513 state:resolved] Get rid of a duplicate set_inverse_instance call if you use new_record(true) (e.g. you want to replace the existing instance). Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
* Set inverse for #replace on a has_one association. [#3513 state:resolved]George Ogata2009-12-281-0/+1
| | | | Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
* Make has_one with :conditions hash scope build or creation of the associated ↵Luciano G Panaro2009-09-281-0/+9
| | | | | | | object with those conditions Signed-off-by: Michael Koziarski <michael@koziarski.com> [#3088 state:committed]
* HasOneAssociation inherits AssociationProxy since it shares nothing with ↵Emilio Tagua2009-06-121-5/+5
| | | | | | | | BelongsToAssociation. [#2796 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Revert "Fixed bug with polymorphic has_one :as pointing to an STI record"Jeremy Kemper2009-05-111-1/+1
| | | | | | [#2594 state:open] This reverts commit 99c103be1165da9c8299bc0977188ecf167e06a5.
* Providing support for :inverse_of as an option to associations.Murray Steele2009-05-041-1/+10
| | | | | | | | | | | | | | | | | | | | | | You can now add an :inverse_of option to has_one, has_many and belongs_to associations. This is best described with an example: class Man < ActiveRecord::Base has_one :face, :inverse_of => :man end class Face < ActiveRecord::Base belongs_to :man, :inverse_of => :face end m = Man.first f = m.face Without :inverse_of m and f.man would be different instances of the same object (f.man being pulled from the database again). With these new :inverse_of options m and f.man are the same in memory instance. Currently :inverse_of supports has_one and has_many (but not the :through variants) associations. It also supplies inverse support for belongs_to associations where the inverse is a has_one and it's not a polymorphic. Signed-off-by: Murray Steele <muz@h-lame.com> Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Fixed bug with polymorphic has_one :as pointing to an STI recordRuy Asan2009-05-011-1/+1
| | | | | | [#2594 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Ensure replacing has_one associations respects the supplied :dependent ↵Dimitri Krassovski2009-03-061-2/+11
| | | | | | option. [#1305 state:resolved] Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* Ensure methods called on association proxies respect access control. [#1083 ↵Pratik Naik2008-10-131-1/+1
| | | | state:resolved] [Adam Milligan, Pratik]
* Add special AssociationReflection methods for creating association objects, ↵Hongli Lai (Phusion)2008-09-091-4/+12
| | | | | | | | and modify the code base to use those methods instead of creating association objects directly. This allows plugins to hook into association object creation behavior. [#986 state:resolved] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Fix that has_one natural assignment to already associated record. [#854 ↵Jakub Kuźma2008-08-211-2/+2
| | | | | | state:resolved] Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* Fix file permissionsTarmo Tänav2008-07-311-0/+0
| | | | Signed-off-by: Joshua Peek <josh@joshpeek.com>
* Add support for :primary_key option to has_one as well as has_many so that a ↵Brad Greenlee2008-07-061-1/+10
| | | | | | key other than the default primary key can be used for the association Signed-off-by: Michael Koziarski <michael@koziarski.com>
* Extract owner_quoted_id so it can be overridden. [#292 state:committed]Andre Arko2008-06-251-2/+2
|
* Added :select option to has_one and belongs_to, remove unused :order option ↵josevalim2008-05-241-2/+3
| | | | | | | on belongs_to. Signed-off-by: Michael Koziarski <michael@koziarski.com> [#241 state:resolved]
* Introduce the :readonly option to all associations. Records from the ↵Jeremy Kemper2008-02-131-1/+2
| | | | | | association cannot be saved. Closes #11084. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8864 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* More thoroughly quote table names. Exposes some issues with sqlite2 adapter. ↵Jeremy Kemper2008-01-051-3/+3
| | | | | | Closes #10698. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8571 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Formatting, grammar and spelling fixes for the associations documentation. ↵Michael Koziarski2007-08-281-1/+1
| | | | | | [seanhussey] Closes #8899 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7368 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* with_scope is protected. Closes #8524.Jeremy Kemper2007-05-301-1/+1
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6909 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* dry up some duplicated codeJamis Buck2007-01-111-37/+21
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5883 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* treat create! like create and make sure the target is loaded firstJamis Buck2007-01-111-0/+1
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5882 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* fix regression in has_one#create, that caused instances thus created to be ↵Jamis Buck2007-01-111-0/+4
| | | | | | orphaned git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5881 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Remove side effects of [5684]Tobias Lütke2006-12-081-2/+2
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5705 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Consolidated different create and create! versions to call through to the ↵Tobias Lütke2006-12-061-3/+30
| | | | | | base class with scope. This fixes inconsistencies, especially related to protected attribtues. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5684 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Backed out of new_record? to new? transformation as it would screw up ↵David Heinemeier Hansson2006-09-051-5/+5
| | | | | | existing models that did boolean calls on "new" attributes [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5018 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Deprecated ActiveRecord::Base.new_record? in favor of ↵David Heinemeier Hansson2006-09-051-5/+5
| | | | | | ActiveRecord::Base.new? (old version still works until Rails 2.0) [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5017 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Rename quote to quote_value so the name can be used in AR models. #3628 [Koz]Michael Koziarski2006-09-041-1/+1
| | | | git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5007 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Use association's :conditions when eager loading. [jeremyevans0@gmail.com] ↵Rick Olson2006-03-161-1/+1
| | | | | | closes #4144 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3897 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Added Base.abstract_class? that marks which classes are not part of the ↵Rick Olson2006-03-161-1/+1
| | | | | | Active Record hierarchy. closes #3704 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3882 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Fixed that calling HasOneProxy#build_model repeatedly would cause saving to ↵David Heinemeier Hansson2006-03-031-1/+1
| | | | | | happen (closes #4058) [anna@wota.jp] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3753 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* save polymorphic joins from the has_many|one association (closes #3812) ↵David Heinemeier Hansson2006-02-121-2/+1
| | | | | | [Rick Olson] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3586 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Polymorphic join support for has_one associations (has_one :foo, :as => ↵Jeremy Kemper2006-02-091-2/+8
| | | | | | :bar). Closes #3785. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3558 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* Added preliminary support for join models [DHH] Added preliminary support ↵David Heinemeier Hansson2005-12-031-13/+14
| | | | | | for polymorphic associations [DHH] Refactored associations to use reflections to get DRYer, beware, major refactoring -- double check before deploying anything with this (all tests pass, but..) git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3213 5ecf4fe2-1ee6-0310-87b1-e25e094e27de