Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created May 20, 2009 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/114857 to your computer and use it in GitHub Desktop.
Save tpitale/114857 to your computer and use it in GitHub Desktop.
#!/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