Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

 state:resolved]
  • Loading branch information...
commit eb1eac93151c1d45c3ef292d99bfcf74799185ea 1 parent e508d9e
@tenderlove tenderlove authored
View
2  activerecord/CHANGELOG
@@ -3,6 +3,8 @@
* Extensions are applied when calling +except+ or +only+ on relations.
Thanks to Iain Hecker.
+* Schemas set in set_table_name are respected by the mysql adapter. LH #5322
+
*Rails 3.0.5 (February 26, 2011)*
* Model.where(:column => 1).where(:column => 2) will always produce an AND
View
18 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -402,14 +402,28 @@ def collation
show_variable 'collation_database'
end
- def tables(name = nil) #:nodoc:
+ def tables(name = nil, database = nil) #:nodoc:
tables = []
- result = execute("SHOW TABLES", name)
+ result = execute(["SHOW TABLES", database].compact.join(' IN '), name)
result.each { |field| tables << field[0] }
result.free
tables
end
+ def table_exists?(name)
+ return true if super
+
+ name = name.to_s
+ schema, table = name.split('.', 2)
+
+ unless table # A table was provided without a schema
+ table = schema
+ schema = nil
+ end
+
+ tables(nil, schema).include? table
+ end
+
def drop_table(table_name, options = {})
super(table_name, options)
end
Please sign in to comment.
Something went wrong with that request. Please try again.