Get the result of an ActiveRecord MySQL query as a hash, not an array

When running a mysql query with ActiveRecord, the Class.connection.execute('query here')result is an array, not a hash in postgres. This is tested with both adapters mysqland mysql2although the default value for mysql2should return the result of the query as a hash.

How can I get ActiveRecordto change the configuration settings in a connection to return the query results as a hash? Can I just not use it ActiveRecordfor this, and should I use a raw mysql2client?

+4
source share
1 answer

, :

data = Class.connection.exec_query('query here'), ActiveRecord::

data.first , .

+14

Source: https://habr.com/ru/post/1538486/


All Articles