Class: ForestAdminAgent::Utils::Schema::GeneratorField

Inherits:
Object
  • Object
show all
Defined in:
lib/forest_admin_agent/utils/schema/generator_field.rb

Constant Summary collapse

RELATION_MAP =
{
  'ManyToMany' => 'BelongsToMany',
  'PolymorphicManyToOne' => 'BelongsTo',
  'ManyToOne' => 'BelongsTo',
  'PolymorphicOneToMany' => 'HasMany',
  'OneToMany' => 'HasMany',
  'PolymorphicOneToOne' => 'HasOne',
  'OneToOne' => 'HasOne'
}.freeze

Class Method Summary collapse

Class Method Details

.build_schema(collection, name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/forest_admin_agent/utils/schema/generator_field.rb', line 15

def self.build_schema(collection, name)
  type = collection.schema[:fields][name].type

  schema = if type == 'Column'
             build_column_schema(collection, name)
           else
             build_relation_schema(collection, name)
           end

  schema.sort_by { |k, _v| k }.to_h
end