You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On a recent project, I needed to prevent admins from deleting photos that are attached to other models. In a normal ActiveRecord model, this is pretty easy to do -- has_many :photo_attachments, dependent: :restrict_with_error. Since I'm using SP, though, I had to do this:
classPhoto < ActiveRecord::BaseextendSimplestPhoto::Model::Photodefdestroyifphoto_attachments.any?errors.add:base,"Photo has attachments and cannot be destroyed"returnfalseendsuperendend
It would be nice for there to be some way to modify the options SP uses, though I don't have any brilliant ideas of how to do that.
The text was updated successfully, but these errors were encountered:
On a recent project, I needed to prevent admins from deleting photos that are attached to other models. In a normal ActiveRecord model, this is pretty easy to do --
has_many :photo_attachments, dependent: :restrict_with_error
. Since I'm using SP, though, I had to do this:It would be nice for there to be some way to modify the options SP uses, though I don't have any brilliant ideas of how to do that.
The text was updated successfully, but these errors were encountered: