diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-18 11:07:03 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-18 11:07:03 +0000 |
commit | bce0e1493024ccfe78efc93da14740a8d503cb7c (patch) | |
tree | f6619f94f9cfa1742eeb0f2acada7b68be27b523 /activerecord/lib/active_record/associations | |
parent | 652f1ef02fdf75e8e971971707b3d5861d06b8be (diff) | |
download | rails-bce0e1493024ccfe78efc93da14740a8d503cb7c.tar.gz rails-bce0e1493024ccfe78efc93da14740a8d503cb7c.tar.bz2 rails-bce0e1493024ccfe78efc93da14740a8d503cb7c.zip |
Fixed that the belongs_to and has_one proxy would fail a test like 'if project.manager' -- this unfortunately also means that you can't call methods like project.manager.build unless there already is a manager on the project #492 [Tim Bates]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@456 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations')
4 files changed, 8 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index f4d8be8b0f..9507822f40 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -11,10 +11,6 @@ module ActiveRecord @loaded = false end - def reload - reset - end - # Add +records+ to this association. Returns +self+ so method calls may be chained. # Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically. def <<(*records) diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index e1dcffe537..009e2ec4c2 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -14,6 +14,11 @@ module ActiveRecord reset end + def reload + reset + load_target + end + def method_missing(symbol, *args, &block) load_target @target.send(symbol, *args, &block) diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 8de48cd880..521aff4058 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -7,11 +7,6 @@ module ActiveRecord @loaded = false end - def reload - reset - load_target - end - def create(attributes = {}) record = build(attributes) record.save @@ -34,12 +29,8 @@ module ActiveRecord @owner[@association_class_primary_key_name] = obj.id unless obj.new_record? end @loaded = true - end - # Ugly workaround - .nil? is done in C and the method_missing trick doesn't work when we pretend to be nil - def nil? - load_target - @target.nil? + return (@target.nil? ? nil : self) end private @@ -65,10 +56,3 @@ module ActiveRecord end end end - -class NilClass #:nodoc: - # Ugly workaround - nil comparison is usually done in C and so a proxy object pretending to be nil doesn't work. - def ==(other) - other.nil? - end -end diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 74e82f146a..30704b6f7e 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -25,9 +25,9 @@ module ActiveRecord @loaded = true unless @owner.new_record? or obj.nil? or dont_save - return (obj.save ? obj : false) + return (obj.save ? self : false) else - return obj + return (obj.nil? ? nil : self) end end |