Method: Gadget.dependencies
- Defined in:
- lib/gadget.rb
.dependencies(conn, *args) ⇒ Object
Return a collection enumerating the dependencies between tables in a database. A table a is considered to be dependent on a table b if a has a foreign key constraint that refers to b.
Usage
dependencies = Gadget.dependencies(conn)
Parameters
-
conn- aPG::Connectionto the database
Returns
-
a Hash:
- table name
-
an Array of table names
257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/gadget.rb', line 257 def self.dependencies(conn, *args) _ = args. tables = self.tables(conn) foreign_keys = self.foreign_keys(conn) tables.reduce({}) do | h, (tablename, _) | h[tablename] = [] refs = foreign_keys[tablename] unless refs.nil? refs[:refs].each { | ref | h[tablename] << ref[:ref_name] } end h end end |