Skip to content

Instantly share code, notes, and snippets.

@tillsc
Created March 8, 2012 09:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tillsc/1999795 to your computer and use it in GitHub Desktop.
Save tillsc/1999795 to your computer and use it in GitHub Desktop.
all_errors helper method for DataMapper 1.2
module DataMapper
module MyHelpers
def all_errors(seen=[])
return [] if seen.include?(self)
seen << self
res = self.errors
parent_relationships.each do |relationship|
association = relationship.get!(self)
if association.dirty?
err = association.all_errors(seen)
res[relationship.name] = err if err.any?
end
end
child_relationships.each do |relationship|
coll = relationship.get_collection(self)
if coll.loaded? # We don't think there are errors on unloaded relationships
coll.each do |association|
if association.dirty?
err = association.all_errors(seen)
(res[relationship.name] ||= []) << err if err.any?
end
end
end
end
res
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment