Skip to content

Instantly share code, notes, and snippets.

@sbfaulkner
Created February 5, 2009 07:03
Show Gist options
  • Save sbfaulkner/58583 to your computer and use it in GitHub Desktop.
Save sbfaulkner/58583 to your computer and use it in GitHub Desktop.
an alternate (more aggressive) approach to making to_yaml work
module ActiveRecord
class Base
def to_yaml_with_association_pruning(opts = {})
# detect and remove any cached associations
self.class.reflect_on_all_associations.each do |a|
ivar = "@#{a.name}"
remove_instance_variable(ivar) if instance_variable_defined?(ivar)
end
to_yaml_without_association_pruning(opts)
end
alias_method_chain :to_yaml, :association_pruning
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment