Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk save via argument to save, update, create #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/couchrest/model/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Persistence
# Create the document. Validation is enabled by default and will return
# false if the document is not valid. If all goes well, the document will
# be returned.
def create(options = {})
def create(options = {}, bulk = false)
return false unless perform_validations(options)
_run_create_callbacks do
_run_save_callbacks do
set_unique_id if new? && self.respond_to?(:set_unique_id)
result = database.save_doc(self)
result = database.save_doc(self, bulk = bulk)
ret = (result["ok"] == true) ? self : false
@changed_attributes.clear if ret && @changed_attributes
ret
Expand All @@ -27,14 +27,14 @@ def create!(options = {})

# Trigger the callbacks (before, after, around)
# only if the document isn't new
def update(options = {})
def update(options = {}, bulk = false)
raise "Cannot save a destroyed document!" if destroyed?
raise "Calling #{self.class.name}#update on document that has not been created!" if new?
return false unless perform_validations(options)
return true if !self.disable_dirty && !self.changed?
_run_update_callbacks do
_run_save_callbacks do
result = database.save_doc(self)
result = database.save_doc(self, bulk = bulk)
ret = result["ok"] == true
@changed_attributes.clear if ret && @changed_attributes
ret
Expand All @@ -43,8 +43,8 @@ def update(options = {})
end

# Trigger the callbacks (before, after, around) and save the document
def save(options = {})
self.new? ? create(options) : update(options)
def save(options = {}, bulk = false)
self.new? ? create(options, bulk) : update(options, bulk)
end

# Saves the document to the db using save. Raises an exception
Expand Down