Skip to content

Instantly share code, notes, and snippets.

@pathsny
Created March 20, 2010 08:07
Show Gist options
  • Save pathsny/338549 to your computer and use it in GitHub Desktop.
Save pathsny/338549 to your computer and use it in GitHub Desktop.
module DataMapper
class Collection
def update!(attributes = {})
assert_update_clean_only(:update!)
model = self.model
model_inst = model.new(attributes)
dirty_attributes = model_inst.dirty_attributes
if dirty_attributes.empty?
true
elsif dirty_attributes.any? { |property, value| !property.valid?(property.get!(model_inst)) }
false
else
unless _update(dirty_attributes)
return false
end
if loaded?
each do |resource|
dirty_attributes.each { |property, value| property.set!(resource, value) }
repository.identity_map(model)[resource.key] = resource
end
end
true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment