Class: TableSaw::DependencyGraph::HasManyDirectives

Inherits:
Object
  • Object
show all
Defined in:
lib/table_saw/dependency_graph/has_many_directives.rb

Constant Summary collapse

QUERY =
<<~SQL
  select %{primary_key} from %{table} where %{clause} and %{polymorphic}
SQL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest, directive) ⇒ HasManyDirectives

Returns a new instance of HasManyDirectives.



12
13
14
15
# File 'lib/table_saw/dependency_graph/has_many_directives.rb', line 12

def initialize(manifest, directive)
  @manifest = manifest
  @directive = directive
end

Instance Attribute Details

#directiveObject (readonly)

Returns the value of attribute directive.



10
11
12
# File 'lib/table_saw/dependency_graph/has_many_directives.rb', line 10

def directive
  @directive
end

#manifestObject (readonly)

Returns the value of attribute manifest.



10
11
12
# File 'lib/table_saw/dependency_graph/has_many_directives.rb', line 10

def manifest
  @manifest
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
# File 'lib/table_saw/dependency_graph/has_many_directives.rb', line 17

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