Why does Rails 3 with Mysql2 Gem ActiveRecord::Base.connection.execute(sql) return Array not Hash?

前端 未结 5 1399
深忆病人
深忆病人 2021-01-31 22:43

I\'m in the process of upgrading an application to Rails 3. I\'ve decided to go with the mysql2 gem. There\'s some legacy code in the app that makes calls like:

         


        
5条回答
  •  梦毁少年i
    2021-01-31 22:56

    If you just want to reuse the database.yml configuration, you can do this:

    config = ActiveRecord::Base.configurations[RAILS_ENV].symbolize_keys
    conn = Mysql2::Client.new(config)
    conn.query("select * from users").each do |user|
      # user should be a hash
    end
    

提交回复
热议问题