Replies: 2 comments 2 replies
-
Currently, you should use In terms of actually fixing this, the constraint_validations metadata table doesn't currently support the |
Beta Was this translation helpful? Give feedback.
-
Can you try this patch?: diff --git a/lib/sequel/plugins/constraint_validations.rb b/lib/sequel/plugins/constraint_validations.rb
index c84179773..08b42fe4b 100644
--- a/lib/sequel/plugins/constraint_validations.rb
+++ b/lib/sequel/plugins/constraint_validations.rb
@@ -125,14 +125,15 @@ module Sequel
ds = @dataset.with_quote_identifiers(false)
table_name = ds.literal(ds.first_source_table)
reflections = {}
- @constraint_validations = (Sequel.synchronize{hash[table_name]} || []).map{|r| constraint_validation_array(r, reflections)}
+ allow_missing_columns = db_schema.select{|col, sch| sch[:allow_null] == false && nil != sch[:default]}.map(&:first)
+ @constraint_validations = (Sequel.synchronize{hash[table_name]} || []).map{|r| constraint_validation_array(r, reflections, allow_missing_columns)}
@constraint_validation_reflections = reflections
end
end
# Given a specific database constraint validation metadata row hash, transform
# it in an validation method call array suitable for splatting to send.
- def constraint_validation_array(r, reflections)
+ def constraint_validation_array(r, reflections, allow_missing_columns=EMPTY_ARRAY)
opts = {}
opts[:message] = r[:message] if r[:message]
opts[:allow_nil] = true if db.typecast_value(:boolean, r[:allow_nil])
@@ -191,11 +192,13 @@ module Sequel
reflection_opts[:argument] = arg
end
- a << column
- unless opts.empty?
- a << opts
+ opts[:from] = :values
+ if column.is_a?(Symbol) && allow_missing_columns.include?(column)
+ opts[:allow_missing] = true
end
+ a << column << opts
+
if column.is_a?(Array) && column.length == 1
column = column.first
end This should fix the issue. I'll do some more testing with it tomorrow, but assuming no problems, I'll probably commit it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In order to have a single source of truth it would be neat that the constraint_validations extension respected the default values at the time of initialization (or otherwise, validation) of an object.
Currently a validation error is thrown if one does not initialize the default values already set by the database, and the attribute is required.
Beta Was this translation helpful? Give feedback.
All reactions