Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the validation rules required for different actions?

I have a model that looks like this -

class Car < ActiveRecord::Base
  validates :name,:presence =>true
end

Can I set it up so that the car's name is not required when preforming a create action but it is required when doing an 'edit' action?

like image 392
Finnnn Avatar asked Dec 02 '11 12:12

Finnnn


People also ask

How do you change a validation rule?

To edit the validation rule for a custom activity field, select the validation rule from Setup by entering Activities in the Quick Find box, then selecting Activities and choose Task Validation Rules or Event Validation Rules. Enter the properties of your validation rule.

Can I deploy so many validation rules at once in production?

Never, ever, ever create validation rules directly in the Production environment. Run rules so narrowly as possible. Remember to notify users when there are new rules. Be careful not to create too many rules.

Do validation rules get enforced on any of the custom field in Salesforce?

The detail page of a custom activity field doesn't list associated validation rules. Workflow rules and some processes can invalidate previously valid fields. Invalidation occurs because updates to records based on workflow rules and also on process scheduled actions don't trigger validation rules.


1 Answers

Yup, that's possible:

class Car < ActiveRecord::Base
  validates :name, presence: true, on: :update
end

Might have a look at the Active Record Validations and Callbacks Guide.

like image 61
tbuehlmann Avatar answered Sep 30 '22 03:09

tbuehlmann