Turn of a single validation

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.

On Feb 26, 3:18 am, Ralph S. [email protected] 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
http://guides.rubyonrails.org/migrations.html#using-models-in-your-migrations
)

Fred

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

On 26 February 2010 13:24, Ralph S. [email protected] 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

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.

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.

On Fri, Feb 26, 2010 at 7:39 PM, Ralph S. [email protected]
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.

On Feb 26, 6:39 pm, Ralph S. [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs