Method: ActivemodelObjectInfo::TableDefinition#operation_columns
- Defined in:
- lib/activemodel_object_info/table_definition.rb
#operation_columns(*fields, **options) ⇒ Object
生成操作相关的字段。包含操作人、操作时间等信息。
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/activemodel_object_info/table_definition.rb', line 39 def operation_columns(*fields, **) # puts "operation_columns(#{fields}, #{options})" # 初始化设置选项 with_operator = [:with_operator].nil? ? true : [:with_operator] = [:with_timestamp].nil? ? true : [:with_timestamp] operator_prefix = [:operator_prefix] operator_suffix = [:operator_suffix] || '_by' = [:timestamp_prefix] = [:timestamp_suffix] || '_at' # 依照每个字段进行设置 fields.each do |field| # 如果要生成操作人信息 if with_operator operator_column_name = operator_prefix.to_s + field.to_s + operator_suffix.to_s column(operator_column_name, :bigint, index: true, comment: '操作人') if operator_column_name.present? end # 如果要生成操作时间戳信息 if = .to_s + field.to_s + .to_s column(, :datetime, index: true, comment: '操作时间戳') if .present? end end end |