r = User.reflections[:book]
r.instance_eval {new_klass = Object.const_get(@klass.name); @klass = 
new_klass}
fixes the problem. So now I need to find where to put this.

 def reverse_reflection(association_name)
        refl = reflections[association_name.to_sym] or raise "No reverse 
reflection for #{name}.#{association_name}"

Aha!

*Here is the solution...*

Define a file *lib/bug_fix.rb*
module BugFix

  def self.apply
    ActiveRecord::Base.descendants.select do |k|
      k.respond_to? :reverse_reflection and k.include BugFix::HoboModel
    end
  end

  module HoboModel
    def self.included(base)
      base.include Instance
    end
    
    module Instance
      def reverse_reflection(association_name)
        begin
          super
        rescue Exception=>e
          refl = reflections[association_name.to_sym] or raise "No reverse 
reflection for #{name}.#{association_name}"
          other_end = refl.klass
          # Put the new klasses
          other_end.reflections.values.each do |r|
            r.instance_eval {new_klass = Object.const_get(@klass.name)
                             @klass = new_klass}
          end
          # Now retry
          super
        end
      end
    end
  end
  
end

Class in a config/initializers file:
BugFix.apply

This is a rails bug. And hobo is suffering from it. Now I can go on happily 
until rails fixes the problem or we patch hobo.




-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to