Permalink
Browse files

[activerecord][postgresql] verify if table has a schema(not public)

  • Loading branch information...
1 parent 055c6fb commit c44418ea4e09cc81da47edbc9ac5f31c7e32c1b4 @lucasts lucasts committed May 27, 2011
Showing with 5 additions and 6 deletions.
  1. +5 −6 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
View
11 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -659,7 +659,10 @@ def drop_database(name) #:nodoc:
# Returns the list of all tables in the schema search path or a specified schema.
def tables(name = nil)
query(<<-SQL, 'SCHEMA').map { |row| row[0] }
- SELECT tablename
+ SELECT case schemaname
+ when 'public' then tablename
+ else schemaname||'.'||tablename
+ end as tablename
FROM pg_tables
WHERE schemaname = ANY (current_schemas(false))
SQL
@@ -830,11 +833,7 @@ def pk_and_sequence_for(table) #:nodoc:
end_sql
# [primary_key, sequence]
- if result.second == 'public' then
- sequence = result.last
- else
- sequence = result.second+'.'+result.last
- end
+ sequence = result.second == 'public' ? result.last : "#{result.second}.#{result.last}"
[result.first, sequence]
rescue

0 comments on commit c44418e

Please sign in to comment.