Skip to content

Instantly share code, notes, and snippets.

@paul
Created September 8, 2008 22:23
Show Gist options
  • Save paul/9557 to your computer and use it in GitHub Desktop.
Save paul/9557 to your computer and use it in GitHub Desktop.
diff --git a/lib/dm-core/resource.rb b/lib/dm-core/resource.rb
index 225200d..8eb59bf 100644
--- a/lib/dm-core/resource.rb
+++ b/lib/dm-core/resource.rb
@@ -40,6 +40,10 @@ module DataMapper
model.const_set('Resource', self) unless model.const_defined?('Resource')
extra_inclusions.each { |inclusion| model.send(:include, inclusion) }
descendants << model
+ class << model
+ @_valid_model = false
+ attr_reader :_valid_model
+ end
end
# Return all classes that include the DataMapper::Resource module
@@ -571,8 +575,9 @@ module DataMapper
assert_valid_model
self.attributes = attributes
end
-
+
def assert_valid_model # :nodoc:
+ return if self.class._valid_model
properties = self.properties
if properties.empty? && relationships.empty?
@@ -582,6 +587,8 @@ module DataMapper
if properties.key.empty?
raise IncompleteResourceError, "#{model.name} must have a key."
end
+
+ class << self; @_valid_model = true; end
end
# TODO document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment