paranoia_uniqueness_validator
paranoia_uniqueness_validator copied to clipboard
Specifying the column name?
I've use an external database (schema is not under my control) that has a field , "deleted_timestamp" instead of "deleted_at".
acts_as_paranoid accepts a column name, like this:
acts_as_paranoid column: :account_deleted_ts
Is there any way to tell this validator to use a different column?
ps. I'm using paranoia_uniqueness_validator ~> 0.1.0 for my crusty old Rails 3.2 app. (shame)
Unfortunately, no. I would love to support that though. A PR would be welcome.
I'm game to take that on. Do you have a preference for what the interface might look like?
I would say add a column option to the validator. So it would look something like this.
validates :field, uniqueness_without_deleted: true, column: :my_column
What do you think?
Looks reasonable. I'll take a stab at that next week.
And in case I don't get around to it, and someone else needs this, here's a close workaround:
validates :user_name, uniqueness: { scope: :deleted_timestamp }
I think this is not quite perfect, as I believe it would not allow two users with the same user_name to be deleted at the same timestamp. But, that's not a real-world problem for me, and might not be for you.