Created
December 13, 2016 22:50
-
-
Save kml/c7264eb3a945e72531bb103e5eca314f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# encoding: utf-8 | |
=begin | |
Mongoid::Errors::ReadonlyDocument: | |
message: | |
Attempted to persist the readonly document 'Offer'. | |
summary: | |
Documents loaded from the database using #only cannot be persisted. | |
resolution: | |
Don't attempt to persist documents that are flagged as readonly. | |
=end | |
# https://github.com/mongodb/mongoid/blob/5.0.0-stable/lib/mongoid/stateful.rb#L72 | |
require "mongoid/document" | |
unless Class.new.tap { |klass| klass.send(:include, Mongoid::Document) }.instance_methods.include?(:readonly?) | |
abort "#{__FILE__}: Mongoid::Document does not include #readonly? method that is going to be patched" | |
end | |
module Mongoid | |
module Document | |
def readonly? | |
#__selected_fields != nil | |
#-> | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment