Skip to content

Instantly share code, notes, and snippets.

@advorak
Created April 6, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save advorak/10010122 to your computer and use it in GitHub Desktop.
Save advorak/10010122 to your computer and use it in GitHub Desktop.
require 'active_support/all'
require 'active_record'
class WordpressConnection < ActiveRecord::Base
end
WordpressConnection.establish_connection adapter: 'mysql2', username: 'root', password: 'password', host: 'localhost', database: 'wordpress_wordpress'
class WordpressConnection::User < WordpressConnection
self.table_name = 'wp_users'
end
WordpressConnection::User.all
__END__
# I don't want it to be looking at table 'wordpress_wordpress.wordpress_connections'
# I want it to be looking at table 'wordpress_wordpress.wp_users'
# I want to create a single connection/class through which
# The result of the above code is as follows:
irb(main):013:0* WordpressConnection::User.all
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'wordpress_wordpress.wordpress_connections' doesn't exist: SHOW FULL FIELDS FROM `wordpress_connections`
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `query'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `block in execute'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `execute'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/mysql2_adapter.rb:222:in `execute'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:301:in `execute_and_free'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:462:in `columns'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/model_schema.rb:208:in `columns'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/model_schema.rb:254:in `column_names'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/attribute_methods.rb:53:in `block in define_attribute_methods'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/mutex_m.rb:73:in `synchronize'
... 6 levels...
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/attribute_methods.rb:191:in `respond_to?'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:368:in `__define_callbacks'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:79:in `run_callbacks'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/core.rb:210:in `init_with'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/persistence.rb:55:in `instantiate'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/querying.rb:45:in `block in find_by_sql'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/result.rb:21:in `block in each'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/result.rb:21:in `each'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/result.rb:21:in `each'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/querying.rb:45:in `map'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/querying.rb:45:in `find_by_sql'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/relation.rb:585:in `exec_queries'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/relation.rb:471:in `load'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/relation.rb:220:in `to_a'
from /home/advorak/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1/lib/active_record/relation.rb:573:in `inspect'
from /home/advorak/.rbenv/versions/2.0.0-p247/bin/irb:12:in `<main>'irb(main):014:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment