how to add the condition in rails and no error give - how , :string, default: [], array: true

 , :string, default: [], array: true



first change column_type to string from integer 

 1. add new migration 

  2. add condition in migration 

class AddExecuteOnToApprovals < ActiveRecord::Migration[6.0]

  def change

    unless ActiveRecord::Base.connection.column_exists?(:approvals, :execute_on)

      add_column :approvals, :execute_on, :string, default: [], array: true

    end

  end

end


3. set enum in model for string with add_array condition :: 

self.table_name = :approvals
# enum execute_on: [:record_creation, :record_edit]
enum status: [:approved, :not_approved]
enum execute_on: { "record_creation" => "record_creation", "record_edit" => "record_edit" }

Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5