Class: ViewModel::PostgreSQLAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/adapters/postgresql_adapter.rb

Class Method Summary collapse

Methods inherited from AbstractAdapter

get_model

Class Method Details

.get_dependencies(connection, table_name) ⇒ Object

returns an Array of Dependent models



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/adapters/postgresql_adapter.rb', line 6

def self.get_dependencies(connection, table_name)
  sql = "select distinct(cl2.relname) from pg_depend dep
        join pg_class cl ON dep.refobjid = cl.oid
        join pg_rewrite on dep.objid = pg_rewrite.oid
        join pg_class cl2 on pg_rewrite.ev_class = cl2.oid
        where cl.relname='#{table_name}' and cl2.relname != '#{table_name}' and deptype='n' "
  result = connection.execute(sql)
  view_dependencies = []
  result.each do |row|
    view_dependencies << get_model(row["relname"])
  end
  if view_dependencies.size > 0
    puts "found dependencies: "
    puts view_dependencies.inspect
  end
  view_dependencies      
end