Skip to content

Commit

Permalink
Define underlying type for enums to be always string
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Nov 19, 2024
1 parent 890138a commit 7f2f109
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/typelizer/model_plugins/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def infer_types(prop)
prop.type = @config.type_mapping[column.type]
prop.comment = comment_for(prop)
prop.enum = enum_for(prop)
prop.type = :string if prop.enum # Ignore underlying column type for enums

prop
end
Expand Down
2 changes: 1 addition & 1 deletion spec/app/app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Post < ApplicationRecord
belongs_to :user

enum category: [:news, :article, :blog].index_by(&:itself)
enum category: { news: 1, article: 2, blog: 3 }
end
2 changes: 1 addition & 1 deletion spec/app/db/migrate/20240707052907_create_posts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreatePosts < ActiveRecord::Migration[7.1]
def change
create_table :posts do |t|
t.string :title
t.string :category
t.integer :category
t.text :body
t.datetime :published_at
t.references :user, null: false, foreign_key: true
Expand Down

0 comments on commit 7f2f109

Please sign in to comment.