There are CONSUL installations where the validations CONSUL offers by
default don't make sense because they're using a different business
logic. Removing these validations in a custom model was hard, and that's
why in many cases modifying the original CONSUL models was an easier
solution.
Since modifying the original CONSUL models makes the code harder to
maintain, we're now providing a way to easily skip validations in a
custom model. For example, in order to skip the price presence
validation in the Budget::Heading model, we could write a model in
`app/models/custom/budget/heading.rb`:
```
require_dependency Rails.root.join("app", "models", "budget", "heading").to_s
class Budget::Heading
skip_validation :price, :presence
end
```
In order to skip validation on translatable attributes (defined with
`validates_translation`), we have to use the
`skip_translation_validation` method; for example, to skip the proposal
title presence validation:
```
require_dependency Rails.root.join("app", "models", "proposal").to_s
class Proposal
skip_translation_validation :title, :presence
end
```
Co-Authored-By: taitus <sebastia.roig@gmail.com>
14 lines
285 B
Ruby
14 lines
285 B
Ruby
class ApplicationRecord < ActiveRecord::Base
|
|
include HumanName
|
|
include SkipValidation
|
|
self.abstract_class = true
|
|
|
|
def self.sample(count = 1)
|
|
if count == 1
|
|
reorder(Arel.sql("RANDOM()")).first
|
|
else
|
|
reorder(Arel.sql("RANDOM()")).limit(count)
|
|
end
|
|
end
|
|
end
|