Sha256: 3fab3bb94a8f6c7d7086661a7f15012a44974688b4e8a814981c1e28e161c761

Contents?: true

Size: 1.04 KB

Versions: 32

Compression:

Stored size: 1.04 KB

Contents

module ForestAdminDatasourceToolkit
  module Components
    module Query
      class ProjectionFactory
        include ForestAdminDatasourceToolkit::Utils
        def self.all(collection)
          projection_fields = collection.schema[:fields].reduce([]) do |memo, path|
            column_name = path[0]
            schema = path[1]
            memo += [column_name] if schema.type == 'Column'

            if schema.type == 'OneToOne' || schema.type == 'ManyToOne'
              relation = collection.datasource.get_collection(schema.foreign_collection)
              relation_columns = relation.schema[:fields]
                                         .select { |_column_name, relation_column| relation_column.type == 'Column' }
                                         .keys
                                         .map { |relation_column_name| "#{column_name}:#{relation_column_name}" }

              memo += relation_columns
            end

            memo
          end

          Projection.new projection_fields
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
forest_admin_datasource_toolkit-1.0.0.pre.beta.61 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.60 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.59 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.58 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.57 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.56 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.55 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.54 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.53 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.52 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.45 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.44 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.43 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.42 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.41 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.40 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.39 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.38 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.37 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb
forest_admin_datasource_toolkit-1.0.0.pre.beta.36 lib/forest_admin_datasource_toolkit/components/query/projection_factory.rb