Skip to content

Instantly share code, notes, and snippets.

@kml
Created December 13, 2016 22:50
Show Gist options
  • Save kml/c7264eb3a945e72531bb103e5eca314f to your computer and use it in GitHub Desktop.
Save kml/c7264eb3a945e72531bb103e5eca314f to your computer and use it in GitHub Desktop.
# 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