# Getting Acts\_as\_Paranoid to work with validates\_uniqueness\_o

**URL:** <https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372>\
**Category:** Rails\
**Created:** [March 2, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372 "2006-03-02T20:41:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [March 2, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372/1 "2006-03-02T20:41:59Z")

</div>

Hello  
I’ve been using Acts\_as\_Parnoid for a while and it has been working well  
but I am now having a slight issue with it. I have a company table were  
I would like to use validates\_uniqueness\_of :company\_name. This  
validation works if a company exists in the database and has not been  
deleted. However, I also would like the validates\_uniqueness\_of to  
work if a company has previously been deleted and has been flagged in  
the deleted\_at column. Currently, if a company has been deleted, it is  
possible to create another company with the same name. I would like to  
bring up a validation message to inform the user. Is there an easy way  
to accomplish this?

Any help would be greatly appreciated.

Harvey

---

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [March 2, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372/2 "2006-03-02T21:01:51Z")

</div>

Harvey B. wrote:

> to accomplish this?
> 
> Any help would be greatly appreciated.

Two questions:

1. If you want to create a company with the same name as something  
already deleted, is it OK to resurrect the old company and use that  
record?
2. If not, then perhaps you can have two companies with the same  
name–so validates\_uniqueness\_of would not be correct?

Basically you have to decide what you want to do with the conflict. If  
a company exists with the name that you want to use but it’s status is  
deleted, you can either reuse the company (reinstating it), or you will  
have to reject the new company because its name is not unique. The only  
way out is to allow two companies with the same name. You’d be  
surprised how many companies in Northern Virginia contract the  
abbreviations for the area in there name: NoVa. Most of them only  
differentiate by adding a little extra to the name like Nova Community  
College, Nova Medical Center, Nova Contracting, etc.

I’d say that both validates\_uniqueness\_of and acts\_as\_paranoid are doing  
their jobs correctly.

---

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [March 2, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372/3 "2006-03-02T21:05:18Z")

</div>

Berin L. wrote:

> > company with the same name. I would like to bring up a validation
> 
> 1. If not, then perhaps you can have two companies with the same  
> College, Nova Medical Center, Nova Contracting, etc.  
> Ok, never mind, I should reread the message again before sending…

You want it to behave properly and it isn’t throwing the validation you  
want. Got it.

---

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [March 3, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372/4 "2006-03-03T20:44:59Z")

</div>

Berin  
Thanks for your help. I was thinking about writing overriding the  
validate method and testing for the condition myself. I’m not entirely  
sure if this is the best way to proceed? So any help would be greatly  
appreciatd  
Thank you

Regards  
Harvey

---

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [March 2, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/getting-acts-as-paranoid-to-work-with-validates-uniqueness-o/54372/5 "2006-03-02T21:14:13Z")

</div>

Harvey B. wrote:

> to accomplish this?
> 
> Any help would be greatly appreciated.

Looking at the plugin code, you would have to specify the option  
:with\_deleted =\> true to find companies that have been deleted. The  
full list of options for find with this plugin is:

[:conditions, :include, :joins, :limit, :offset, :order, :select,  
:readonly, :group, :from, :with\_deleted]

Not sure how validates\_uniqueness\_of works. I’ll look into that next.
