Skip to content

Commit 661ace4

Browse files
committed
fix: include more checks for presence validations
1 parent 56c35be commit 661ace4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/anchor/resource.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ def anchor_attributes_properties(included_fields:)
8080
if check_presence && _model_class.validators_on(model_method).any? do |v|
8181
if v.is_a?(ActiveRecord::Validations::UniquenessValidator)
8282
opts = v.options.with_indifferent_access
83-
!(opts[:allow_nil] || opts[:allow_blank])
83+
!(opts[:allow_nil] || opts[:allow_blank] || opts[:if] || opts[:unless] || opts[:on])
8484
elsif v.is_a?(ActiveRecord::Validations::NumericalityValidator)
8585
opts = v.options.with_indifferent_access
86-
!opts[:allow_nil]
87-
else
88-
v.is_a?(ActiveRecord::Validations::PresenceValidator)
86+
!(opts[:allow_nil] || opts[:if] || opts[:unless] || opts[:on])
87+
elsif v.is_a?(ActiveRecord::Validations::PresenceValidator)
88+
opts = v.options.with_indifferent_access
89+
!(opts[:if] || opts[:unless] || opts[:on])
8990
end
9091
end
9192
type.type

0 commit comments

Comments
 (0)