Module: SchemaPlus::ForeignKeys::ActiveRecord::ConnectionAdapters::PostgresqlAdapter

Defined in:
lib/schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter.rb

Overview

The Postgresql adapter implements the SchemaPlus::ForeignKeys extensions and enhancements

Instance Method Summary collapse

Instance Method Details

#foreign_keys(table_name, name = nil) ⇒ Object

:nodoc:



9
10
11
12
13
14
15
16
17
18
# File 'lib/schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter.rb', line 9

def foreign_keys(table_name, name = nil) #:nodoc:
  load_foreign_keys(<<-SQL, name)
SELECT f.conname, pg_get_constraintdef(f.oid), t.relname
  FROM pg_class t, pg_constraint f
 WHERE f.conrelid = t.oid
   AND f.contype = 'f'
   AND t.relname = '#{table_name_without_namespace(table_name)}'
   AND t.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = #{namespace_sql(table_name)} )
  SQL
end

#reverse_foreign_keys(table_name, name = nil) ⇒ Object

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter.rb', line 20

def reverse_foreign_keys(table_name, name = nil) #:nodoc:
  load_foreign_keys(<<-SQL, name)
SELECT f.conname, pg_get_constraintdef(f.oid), t2.relname
  FROM pg_class t, pg_class t2, pg_constraint f
 WHERE f.confrelid = t.oid
   AND f.conrelid = t2.oid
   AND f.contype = 'f'
   AND t.relname = '#{table_name_without_namespace(table_name)}'
   AND t.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = #{namespace_sql(table_name)} )
  SQL
end