Skip to content

Commit

Permalink
[#888] fix behavior for has_one without causing excessive loading
Browse files Browse the repository at this point in the history
  • Loading branch information
al2o3cr committed Feb 16, 2011
1 parent a9c7cb1 commit 24b4562
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hobo/lib/active_record/association_collection.rb
Expand Up @@ -29,6 +29,22 @@ def member_class
proxy_reflection.klass
end

# DO NOT call super here - AssociationProxy's version loads the collection, and that's bad.
# TODO: this really belongs in Rails; migrate it there ASAP
def respond_to?(*args)
return super if has_one_collection?
proxy_respond_to?(*args) || [].respond_to?(*args)
end

def is_a?(klass)
if has_one_collection?
load_target
@target.is_a?(klass)
else
[].is_a?(klass)
end
end

private

def set_reverse_association(object)
Expand All @@ -41,6 +57,10 @@ def set_reverse_association(object)
end
end

def has_one_collection?
proxy_reflection.macro == :has_one
end

end
end
end

0 comments on commit 24b4562

Please sign in to comment.