Harvey Bernstein
2006-Mar-02 19:41 UTC
[Rails] Getting Acts_as_Paranoid to work with validates_uniqueness_of
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 -- Posted with http://DevLists.com. Sign up and save your time!
Berin Loritsch
2006-Mar-02 20:01 UTC
[Rails] Getting Acts_as_Paranoid to work with validates_uniqueness_of
Harvey Bernstein wrote:> 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. >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.
Berin Loritsch
2006-Mar-02 20:05 UTC
[Rails] Getting Acts_as_Paranoid to work with validates_uniqueness_of
Berin Loritsch wrote:> Harvey Bernstein wrote: >> 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. >> > > 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.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.
Berin Loritsch
2006-Mar-02 20:14 UTC
[Rails] Getting Acts_as_Paranoid to work with validates_uniqueness_of
Harvey Bernstein wrote:> 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. >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.
Harvey Bernstein
2006-Mar-03 19:43 UTC
Re: [Rails] Getting Acts_as_Paranoid to work with validates_uniqueness_of
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 On Thursday, March 02, 2006, at 3:14 PM, Berin Loritsch wrote:>Harvey Bernstein wrote: >> 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. >> > >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. > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your time!
Reasonably Related Threads
- can''t get rails to connect to mySQL - HELP!!!!!!!!!
- acts_as_paranoid Unknown key(s): with_deleted
- Problem with acts_as_paranoid: "ArgumentError: Unknown key(s): group"
- How to add a migration with a plugin?
- acts_as_paranoid and Association Extensions (has_one troubles)