Permalink
Browse files

Merge pull request #3867 from jadeforrest/master

Increase performance for table_exists?
  • Loading branch information...
tenderlove committed Dec 5, 2011
2 parents 38185f6 + 73a331c commit 988061ddb802e6803d19de954762753f14551c56
@@ -23,7 +23,12 @@ def table_alias_for(table_name)
# === Example
# table_exists?(:developers)
def table_exists?(table_name)
- tables.include?(table_name.to_s)
+ begin
+ select_value("SELECT 1 FROM #{table_name.to_s} where 1=0")

This comment has been minimized.

Show comment Hide comment
@jeremy

jeremy Dec 5, 2011

Owner

Table name needs quoting

@jeremy

jeremy Dec 5, 2011

Owner

Table name needs quoting

This comment has been minimized.

Show comment Hide comment
@tenderlove

tenderlove Dec 5, 2011

Owner

Fisted in 8aa7b86

+ true
+ rescue
+ false
+ end
end
# Returns an array of indexes for the given table.

0 comments on commit 988061d

Please sign in to comment.