# Turn of a single validation

**URL:** <https://www.ruby-forum.com/t/turn-of-a-single-validation/184175>\
**Category:** Rails\
**Created:** [February 26, 2010, 4:18am UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175 "2010-02-26T04:18:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 26, 2010, 4:18am UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/1 "2010-02-26T04:18:22Z")

</div>

During migration I would like to turn off a single validation.

That is, I don’t want to turn off all validations for a single record, I  
want to turn of a single validation (of several) for all records.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 26, 2010, 10:31am UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/2 "2010-02-26T10:31:14Z")

</div>

On Feb 26, 3:18 am, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> During migration I would like to turn off a single validation.
> 
> That is, I don’t want to turn off all validations for a single record, I  
> want to turn of a single validation (of several) for all records.

If you’re using models in a migration you should usually be creating a  
private copy of the class in the migration ie

class SomeMigration \< …  
class SomeModel \< ActiveRecord::Base  
end

def self.up  
…  
end  
end

( see also

> **[Active Record Migrations — Ruby on Rails Guides](https://edgeguides.rubyonrails.org/active_record_migrations.html)**
>
> Active Record MigrationsMigrations are a feature of Active Record that allows you to evolve your database schema over time. Rather than write schema modifications in pure SQL, migrations allow you to use a Ruby DSL to describe changes to your...

)

Fred

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 26, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/3 "2010-02-26T14:24:16Z")

</div>

Frederick C. wrote:

> If you’re using models in a migration you should usually be creating a  
> private copy of the class in the migration ie  
> . . .

Fred, thank you.

What you propose is the right way to do things. I’m looking for the  
wrong way to do things … that is, I’m looking to turn off a validation  
once it has been turned on.

Ralph

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 26, 2010, 2:42pm UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/4 "2010-02-26T14:42:53Z")

</div>

On 26 February 2010 13:24, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> once it has been turned on.  
> I think you missed Frederick’s point, (or I have missed yours). Note  
> that he is suggesting putting a local declaration of your model class  
> _inside_ the migration. This means that any validations in your  
> model.rb file will not be seen. There should not be a need for  
> validations inside a migration, so the fact that all validations are  
> being ignored should not matter. (You are doing a migration not a  
> seed aren’t you?).

class SomeMigration \< …  
class SomeModel \< ActiveRecord::Base  
end

def self.up  
…  
end  
end

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 26, 2010, 9:58pm UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/5 "2010-02-26T21:58:22Z")

</div>

Ralph S. wrote:

> Colin L. wrote:
> 
> > You are doing a migration not a  
> > seed aren’t you?).
> 
> I’m doing a seed with “random” data and I want all the validations …  
> except one.  
> Seeds don’t belong in migrations, and anyway they shouldn’t need you to  
> turn off validations.
> 
> I know. I know. I’m bad bad bad. But this is a hack AND I’d like to  
> Don’t hack. Don’t do things you know are bad. Period.\> know if the hack  
> can be done.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 26, 2010, 7:39pm UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/6 "2010-02-26T19:39:56Z")

</div>

Colin L. wrote:

> You are doing a migration not a  
> seed aren’t you?).

I’m doing a seed with “random” data and I want all the validations …  
except one.

I know. I know. I’m bad bad bad. But this is a hack AND I’d like to  
know if the hack can be done.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 27, 2010, 12:43pm UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/7 "2010-02-27T12:43:50Z")

</div>

On Fri, Feb 26, 2010 at 7:39 PM, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Colin L. wrote:
> 
> > You are doing a migration not a  
> > seed aren’t you?).
> 
> I’m doing a seed with “random” data and I want all the validations …  
> except one.

Another option: If you can trust your seed data save(false) turns off  
validations.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 27, 2010, 11:56am UTC](https://www.ruby-forum.com/t/turn-of-a-single-validation/184175/8 "2010-02-27T11:56:26Z")

</div>

On Feb 26, 6:39 pm, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Colin L. wrote:
> 
> > You are doing a migration not a  
> > seed aren’t you?).
> 
> I’m doing a seed with “random” data and I want all the validations …  
> except one.
> 
> I know. I know. I’m bad bad bad. But this is a hack AND I’d like to  
> know if the hack can be done.

You could probably twist the :if/:unless options for this, although it  
will almost certainly come and bite you later on.

Fred
