Skip to content
This repository
Browse code

schemas set by set_table_name are respected by the mysql adapter. [#5322

state:resolved]
  • Loading branch information...
commit eb1eac93151c1d45c3ef292d99bfcf74799185ea 1 parent e508d9e
Aaron Patterson authored March 21, 2011
2  activerecord/CHANGELOG
@@ -3,6 +3,8 @@
3 3
 * Extensions are applied when calling +except+ or +only+ on relations.
4 4
   Thanks to Iain Hecker.
5 5
 
  6
+* Schemas set in set_table_name are respected by the mysql adapter. LH #5322
  7
+
6 8
 *Rails 3.0.5 (February 26, 2011)*
7 9
 
8 10
 * Model.where(:column => 1).where(:column => 2) will always produce an AND
18  activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -402,14 +402,28 @@ def collation
402 402
         show_variable 'collation_database'
403 403
       end
404 404
 
405  
-      def tables(name = nil) #:nodoc:
  405
+      def tables(name = nil, database = nil) #:nodoc:
406 406
         tables = []
407  
-        result = execute("SHOW TABLES", name)
  407
+        result = execute(["SHOW TABLES", database].compact.join(' IN '), name)
408 408
         result.each { |field| tables << field[0] }
409 409
         result.free
410 410
         tables
411 411
       end
412 412
 
  413
+      def table_exists?(name)
  414
+        return true if super
  415
+
  416
+        name          = name.to_s
  417
+        schema, table = name.split('.', 2)
  418
+
  419
+        unless table # A table was provided without a schema
  420
+          table  = schema
  421
+          schema = nil
  422
+        end
  423
+
  424
+        tables(nil, schema).include? table
  425
+      end
  426
+
413 427
       def drop_table(table_name, options = {})
414 428
         super(table_name, options)
415 429
       end

0 notes on commit eb1eac9

Please sign in to comment.
Something went wrong with that request. Please try again.