Skip to content

Instantly share code, notes, and snippets.

@tpitale

tpitale/gist:114857

Created May 20, 2009
Embed
What would you like to do?
#!/usr/bin/env ruby
#
# A one file test to show ...
require 'rubygems'
require 'dm-core'
# setup the logger
DataMapper::Logger.new(STDOUT, :debug)
# connect to the DB
DataMapper.setup(:default, 'sqlite3::memory:')
class Search
include DataMapper::Resource
property :id, Serial
end
class Result
include DataMapper::Resource
property :id, Serial
belongs_to :search
end
DataMapper.auto_migrate!
# play with this number, and watch the number of subsequent selects change
10.times do
Search.create
end
20.times do
if rand > 0.1
Result.create(:search_id => rand(10)+1)
else
Result.create
end
end
puts "-"*80
Result.all.each do |r|
puts r.search.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.