Skip to content

Commit 5dcad62

Browse files
committed
fix: nullability for enums
1 parent be4bcda commit 5dcad62

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/anchor/resource.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ def anchor_attributes_properties(included_fields:)
7878

7979
enum = Anchor.config.infer_ar_enums && !method_defined && _model_class.try(:defined_enums).try(:[], model_method.to_s)
8080
column = !method_defined && _model_class.try(:columns_hash).try(:[], model_method.to_s)
81-
if enum
82-
Anchor::Types::Union.new(enum.map { |_key, val| Anchor::Types::Literal.new(val) })
83-
elsif column
81+
82+
if column
8483
type = Anchor::Types::Inference::ActiveRecord::SQL.from(column)
84+
85+
if enum
86+
enum_type = Anchor::Types::Union.new(enum.map { |_key, val| Anchor::Types::Literal.new(val) })
87+
type = type.is_a?(Anchor::Types::Maybe) ? Anchor::Types::Maybe.new(enum_type) : enum_type
88+
end
89+
8590
unless description
8691
description = column.comment if Anchor.config.use_active_record_comment
8792
if description && !Anchor.config.ar_comment_to_string.nil?

0 commit comments

Comments
 (0)