The below after create hook does not successfully set the gdoc key. We have to use self.write_attribute instead. Am I trying to do something stupid?
class GoogleDoc
field :gdoc_key, type: String
field :filename, type: String
after_create :after_create_hook
def after_create_hook
self.gdoc_key = "qwerty"
self.save
end
end
Thanks! Jonathan
From Durran
You cannot call save in an after_ hook since you're going to cause the document to fire the callbacks in an infinite loop. You'll need to use something that doesn't fire callbacks, like update_attribute.
https://github.com/mongoid/mongoid/issues/2974
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With