Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading associations doesn't work if class hasn't been loaded #27

Open
ctaintor opened this issue Aug 10, 2010 · 0 comments
Open

Loading associations doesn't work if class hasn't been loaded #27

ctaintor opened this issue Aug 10, 2010 · 0 comments

Comments

@ctaintor
Copy link

I ran into this problem, and, it's not a DJ problem but a YAML and Rails problem. However, since DJ makes use of YAML serializing, it is probably wise to have something like this included in DJ.

#Taken from http://blog.sbf5.com/?p=39
#Basically, when an object is deserialized and the class that was serialized
#doesn't exist, then you get back a YAML object, rather than the object you
#wanted.  The fix below will use Rails' autoloading to load the class if it's
#not already there.
YAML::Syck::Resolver.class_eval do
  def transfer_with_autoload(type, val)
    match = type.match(/object:(\w+(?:::\w+)*)/)
    match && match[1].constantize
    transfer_without_autoload(type, val)
  end
  alias_method_chain :transfer, :autoload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant