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

This commit is contained in:
Lucas Stephanou
2011-05-27 17:48:34 -03:00
parent 055c6fb010
commit c44418ea4e

View File

@@ -659,7 +659,10 @@ module ActiveRecord
# 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 @@ module ActiveRecord
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