Sha256: d221c43dcdeb20301bb79b754d647b53aeffbe43b63148b59bb8c80228752f67
Contents?: true
Size: 1.48 KB
Versions: 5
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true module TableSaw module DependencyGraph class HasManyDirectives attr_reader :manifest, :directive def initialize(manifest, directive) @manifest = manifest @directive = directive end def call valid_associations.map do |table, column| TableSaw::DependencyGraph::AddDirective.new( table, ids: query_result(table, column).map { |r| r[TableSaw.information_schema.primary_keys[table]] }, partial: directive.partial? ) end end private def associations TableSaw.information_schema.has_many.fetch(directive.table_name, []) end # rubocop:disable Metrics/AbcSize def valid_associations associations.select do |table, _column| next false if directive.partial? && !TableSaw.information_schema.primary_keys.key?(table) next true if directive.has_many.include?(table) manifest.has_many.fetch(directive.table_name, []).include?(table) end end # rubocop:enable Metrics/AbcSize def query_result(table, column) return [] unless directive.selectable? TableSaw::Connection.exec( format('select %{primary_key} from %{table} where %{column} in (%{ids})', primary_key: TableSaw.information_schema.primary_keys[table], table: table, column: column, ids: directive.ids.join(',')) ) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems