-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deleted resources can still be associated to other resources #380
Comments
@edwardmp I would add a validation. I think this may be out of the scope of paranoia for creating new resources with the intention of using an object that has been marked as deleted. Some people use paranoia on products and change the Maybe: class Event < ApplicationRecord
belongs_to :card
validate :card_is_alive
private
def card_is_alive
return if card.deleted_at.nil?
errors.add(:card, 'has been deleted')
end
end |
@BenMorganIO
This can then be used as: This might be of use to someone else. Although I agree that by default this would be out of paranoia's scope, might it be an idea to include this validator with paranoia for people to use? |
@edwardmp if you'd like to make a PR to add this validation, I would love to get it merged in :) |
I have been thinking of the same issue - but from a different angle. In my case, I would still like the UI and the model-level validations to go through if I edit the
Please see this gist. If this idea is good, I can make this into a gem and release it soon. (or), I could supply this as a PR for this codebase itself - wdyt? |
Hey @BenMorganIO, I submitted a pull request that includes my validator, a test for it and an updated README. Please merge it in at your discretion. |
I'm not sure whether this is actually expected to happen as this use case may not be within the intended scope of paranoia.
I have a model (let's call it
Card
) that acts as paranoid. I have another model (let's call it 'Event') that doesn't act as paranoid butbelongs_to
aCard
. If I have an instance of aCard
that was soft destroyed, I can still assign it to a newEvent
when I create it.Is this expected behavior when using this gem? If so, does anyone have any suggestions as to how to prevent this (e.g. adding a custom validator checking that associations are not soft deleted before creating a resource)?
The text was updated successfully, but these errors were encountered: