From f2c4dc538e93c3e92d7de6f75bacacd39aeb5074 Mon Sep 17 00:00:00 2001 From: mattkhan <86168986+mattkhan@users.noreply.github.com> Date: Fri, 26 Sep 2025 11:10:09 -0700 Subject: [PATCH] fix: nullability for enums --- lib/anchor/resource.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/anchor/resource.rb b/lib/anchor/resource.rb index 8ff6831..4469134 100644 --- a/lib/anchor/resource.rb +++ b/lib/anchor/resource.rb @@ -78,10 +78,15 @@ def anchor_attributes_properties(included_fields:) enum = Anchor.config.infer_ar_enums && !method_defined && _model_class.try(:defined_enums).try(:[], model_method.to_s) column = !method_defined && _model_class.try(:columns_hash).try(:[], model_method.to_s) - if enum - Anchor::Types::Union.new(enum.map { |_key, val| Anchor::Types::Literal.new(val) }) - elsif column + + if column type = Anchor::Types::Inference::ActiveRecord::SQL.from(column) + + if enum + enum_type = Anchor::Types::Union.new(enum.map { |_key, val| Anchor::Types::Literal.new(val) }) + type = type.is_a?(Anchor::Types::Maybe) ? Anchor::Types::Maybe.new(enum_type) : enum_type + end + unless description description = column.comment if Anchor.config.use_active_record_comment if description && !Anchor.config.ar_comment_to_string.nil?