app/models/unidom/common/concerns/model_extension.rb in unidom-common-0.2 vs app/models/unidom/common/concerns/model_extension.rb in unidom-common-0.3
- old
+ new
@@ -70,9 +70,10 @@
if 'code'==name or name.ends_with? '_code'
class_eval do
if columns_hash[name].null
validates name.to_sym, allow_blank: true, length: { maximum: columns_hash[name].limit }
+ scope "#{name}_length_is".to_sym, ->(length) { where "LENGTH(#{name}) = :length", length: length }
else
validates name.to_sym, presence: true, length: { is: columns_hash[name].limit }
end
scope "#{name}d_as".to_sym, ->(code) { where name => code }
scope "not_#{name}d_as".to_sym, ->(code) { where.not name => code }
\ No newline at end of file