Skip to content

Instantly share code, notes, and snippets.

@tpope
Created April 19, 2017 19:36
Show Gist options
  • Save tpope/1610e14266ca9eaaddaefe9adf665f12 to your computer and use it in GitHub Desktop.
Save tpope/1610e14266ca9eaaddaefe9adf665f12 to your computer and use it in GitHub Desktop.

Revisions

  1. tpope created this gist Apr 19, 2017.
    7 changes: 7 additions & 0 deletions data_from_scope.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    ActiveRecord::Base.connection.select_all(scope.arel).tap do |result|
    result.map do |attrs|
    attrs.each do |k, v|
    attrs[k] = result.column_types[k].type_cast(v)
    end
    end
    end