Rails: how to select_rows with fields names (mysql) -
i looking way result set mysql query similar output of activerecord::base.connection.select_rows includes result's columns names first element.
for example:
activerecord::base.connection.select_rows_with_fields("select id,name users") => [["id", "name"], ["1","amy"],["2","bob"],["3","cam"]]
select_rows_with_fields:
module activerecord module connectionadapters class mysql2adapter def select_rows_with_fields(sql) result = execute(sql) rows = result.to_a rows.unshift(result.fields) end end end end
Comments
Post a Comment