Using Rails Migration on different database than standard “production” or “development”

前端 未结 20 1432
借酒劲吻你
借酒劲吻你 2020-11-29 18:18

I have a rails project running that defines the standard production:, :development and :test DB-connections in config/database.yml

In addition I have a quiz_developm

20条回答
  •  感动是毒
    2020-11-29 19:08

    class Article < ActiveRecord::Base
    
        ActiveRecord::Base.establish_connection(
          :adapter  => "mysql2",
          :host     => "localhost",
          :username => "root",
          :database => "test"
        )
    end
    

    And:

    class Artic < Aritcle
        self.table_name = 'test'
    
        def self.get_test_name()
            query = "select name from testing"
            tst = connection.select_all(query) #select_all is important!
            tst[0].fetch('name')
        end
    end
    

    You can call Artic.get_test_name in order to execute.

提交回复
热议问题