Sha256: 37971aed6c25744cedeeffd0eaae56e23cd29068906f396f4f58b692535eb25a
Contents?: true
Size: 1.33 KB
Versions: 20
Compression:
Stored size: 1.33 KB
Contents
module ForestAdminDatasourceToolkit module Utils class Schema def self.foreign_key?(collection, name) field = collection.schema[:fields][name] field.type == 'Column' && collection.schema[:fields].any? do |_key, relation| relation.type == 'ManyToOne' && relation.foreign_key == name end end def self.primary_key?(collection, name) field = collection.schema[:fields][name] field.type == 'Column' && field.is_primary_key end def self.primary_keys(collection) collection.schema[:fields].keys.select do |field_name| field = collection.schema[:fields][field_name] field.type == 'Column' && field.is_primary_key end end def self.get_to_many_relation(collection, relation_name) unless collection.schema[:fields].key?(relation_name) raise Exceptions::ForestException, "Relation #{relation_name} not found" end relation = collection.schema[:fields][relation_name] if relation.type != 'OneToMany' && relation.type != 'PolymorphicOneToMany' && relation.type != 'ManyToMany' raise Exceptions::ForestException, "Relation #{relation_name} has invalid type should be one of OneToMany or ManyToMany." end relation end end end end
Version data entries
20 entries across 20 versions & 1 rubygems