Sha256: 4878563f4c183393438f543b0c4f1b3e534065d33f932e05de5b03889dca62e5
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 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 |fk| TableSaw::DependencyGraph::AddDirective.new( fk.from_table, ids: query_result(fk).map { |r| r[TableSaw.schema_cache.primary_keys(fk.from_table)] }, partial: directive.partial? ) end end private def associations manifest.associations.has_many.fetch(directive.table_name, Set.new) end # rubocop:disable Metrics/AbcSize def valid_associations associations.select do |fk| next false if directive.partial? && TableSaw.schema_cache.primary_keys(fk.from_table).nil? next true if directive.has_many.key?(fk.from_table) manifest.has_many.fetch(directive.table_name, {}).key?(fk.from_table) end end # rubocop:enable Metrics/AbcSize def query_result(foreign_key) return [] unless directive.selectable? TableSaw::Connection.exec( TableSaw::DependencyGraph::BuildHasManyQuery.new(manifest, directive, foreign_key).call ) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems