Permalink
Browse files

[#1002] break infinite recursion that occurs when you use default_scope

  • Loading branch information...
1 parent 1ad18c0 commit c36ce397cd19bbbb426e889043926b17ecad646d @bryanlarsen bryanlarsen committed Apr 3, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 hobo/lib/hobo/extensions/active_record/relation_with_origin.rb
@@ -11,8 +11,10 @@ def member_class
module SpawnMethods
def merge_with_origin(r)
merged = merge_without_origin(r)
- merged.origin ||= r.respond_to?(:origin) && r.origin
- merged.origin_attribute ||= r.respond_to?(:origin_attribute) && r.origin_attribute
+ # LH#1002: cannot call respond_to? because default_scope ends
+ # up calling merge and we end up with infinite recursion
+ merged.origin = r.origin rescue nil unless merged.instance_variable_defined?("@origin")
+ merged.origin_attribute = r.origin_attribute rescue nil unless merged.instance_variable_defined?("@origin_attribute")
merged
end

0 comments on commit c36ce39

Please sign in to comment.