class Ezframe::ForeignType

Attributes

db_data[RW]

Public Instance Methods

db_type() click to toggle source
# File lib/ezframe/column_type.rb, line 266
def db_type
  return "int"
end
form(opts = {}) click to toggle source
# File lib/ezframe/column_type.rb, line 254
def form(opts = {})
  return nil if no_edit? && !opts[:force]
  view_key = @attribute[:menu_column] || @attribute[:view_column]
  data_h = DB::Cache[target_table.to_sym]
  menu_a = data_h.map do |id, data|
    [ data[:id], data[view_key&.to_sym] ]
  end
  key = self.key
  key ="#{key}#{opts[:key_suffix]}" if opts[:key_suffix]
  return Ht.select(name: key, class: %w[browser-default], item: menu_a, value: @value, after: make_error_box(key))
end
set_db_data() click to toggle source
# File lib/ezframe/column_type.rb, line 270
def set_db_data
  @db_data = {}
  if @value
    @db_data = DB::Cache[target_table.to_sym][@value]
  end
end
target_table() click to toggle source
# File lib/ezframe/column_type.rb, line 236
def target_table
  table = @attribute[:table]
  return table if table
  return self.key
end
view(opts = {}) click to toggle source
# File lib/ezframe/column_type.rb, line 242
def view(opts = {})
  return nil if no_view? && !opts[:force]
  colkey = @attribute[:view_column]
  if @value && colkey
    data_h = DB::Cache[target_table.to_sym]
    data = data_h[@value.to_i]
    return nil unless data
    return data[colkey.to_sym]
  end
  return nil
end