Skip to content

Instantly share code, notes, and snippets.

@indrekj
Created December 19, 2012 18:06
Show Gist options
  • Select an option

  • Save indrekj/4338888 to your computer and use it in GitHub Desktop.

Select an option

Save indrekj/4338888 to your computer and use it in GitHub Desktop.
require "dm-mapper"
require "data_mapper/engine/arel"
DM = DataMapper::Environment.new
DM.engines[:arel] = DataMapper::Engine::Arel::Engine.new("sqlite3:/db/development.sqlite3")
require "virtus"
class Variant
include DataMapper::Model
attribute :id, Integer, key: true
end
DM.build(Variant, :arel) do
key :id
end
DM.finalize
DM[Variant].to_a
# EXCEPTION: => undefined method `to_sym' for 0:Fixnum
# Debugging using debugger
(rdb:1) p relation.class
DataMapper::Engine::Arel::Gateway
(rdb:1) p relation.send(:read)
[{"id"=>1, 0=>1}, {"id"=>2, 0=>2}, {"id"=>3, 0=>3}]
(rdb:1) p relation.send(:to_sql)
"SELECT id FROM \"variants\" "
(rdb:1) p relation.send(:connection).execute("select id from variants")
[{"id"=>1, 0=>1}, {"id"=>2, 0=>2}, {"id"=>3, 0=>3}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment