Closed chrisnicola closed 9 years ago
In the end I solved this but the process is very awkward. Any attempt to set the OID directly will fail. Also if you destroy the old model while it holds the OID reference the OID is destroyed. This works however:
new_model.update_column(:image, old_model.image.identifier)
# Remove the reference to the image from the old_model
old_model.update_column(:image, nil)
# Alternatively you may want to delete the model altogether, be sure to use delete not destroy
OldModel.delete(old_model.id)
Your solution should work fine, the OID is just a number that references to a system table. I actually think that is the most elegant solution. Changing the carrierwave storage to handle this case (updating the OID instead of the whole file) seems even more awkward.
Thanks. I've also updated it to show that the delete
method must be used to avoid triggering the calback that unlinks the large object.
I'm migrating some data to a new model and there doesn't seem to be an easy way to assign the old OID to the new model. This seems to be a Carrierwave limitation though. Are you aware of a way to do this?