Created
October 29, 2012 16:52
-
-
Save dblock/3974846 to your computer and use it in GitHub Desktop.
A monkey patch for detecing nil IDs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mongoid/collection' | |
module Mongoid | |
class Collection | |
alias_method :_update, :update | |
def update(selector, document, options = {}) | |
document.deep_fetch("_id").each do |value| | |
if value.nil? | |
Rails.logger.error "Invalid nil _id in #{document}." | |
raise "Invalid nil _id in #{document}." | |
end | |
end | |
_update selector, document, options | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment