Added new_model? and new_record? alias to casted model for rails compatibility.

This commit is contained in:
Peter Gumeson 2009-05-28 16:09:53 -07:00
parent 9a026997dd
commit 23341f3698
4 changed files with 69 additions and 0 deletions

View file

@ -201,6 +201,7 @@ module CouchRest
raise ArgumentError, "a document requires a database to be saved to (The document or the #{self.class} default database were not set)" unless database
set_unique_id if new_document? && self.respond_to?(:set_unique_id)
result = database.save_doc(self, bulk)
mark_as_saved if result["ok"] == true
result["ok"] == true
end
@ -226,5 +227,22 @@ module CouchRest
end
end
protected
# Set document_saved flag on all casted models to true
def mark_as_saved
self.each do |key, prop|
if prop.is_a?(Array)
prop.each do |item|
if item.respond_to?(:document_saved)
item.send(:document_saved=, true)
end
end
elsif prop.respond_to?(:document_saved)
prop.send(:document_saved=, true)
end
end
end
end
end