· 8 years ago · Apr 07, 2018, 09:50 AM
1require 'rubygems'
2require 'dm-core'
3
4DataMapper::Logger.new($stdout, :debug)
5DataMapper.setup(:default, 'sqlite3:memory:')
6
7class Quote
8 include DataMapper::Resource
9 property :id, Serial
10 has 0..n, :billings, :through => Resource
11end
12
13class Billing
14 include DataMapper::Resource
15 property :id, Serial
16
17 has 0..n, :quotes, :through => Resource
18end
19
20puts DataMapper::Model.descendants.inspect
21
22DataMapper.auto_migrate!
23
24puts DataMapper::Model.descendants.inspect
25
26__END__
27
28[ree-1.8.7-2009.10] mungo:extlib snusnu$ ruby foo.rb
29#<DataMapper::Model::DescendantSet:0x10165a778 @ancestors=nil, @descendants=[Quote, Billing]>
30 ~ (0.000038) SELECT sqlite_version(*)
31 ~ (0.002727) DROP TABLE IF EXISTS "quotes"
32 ~ (0.002216) DROP TABLE IF EXISTS "billings"
33 ~ (0.002530) DROP TABLE IF EXISTS "billing_quotes"
34 ~ (0.000024) PRAGMA table_info("quotes")
35 ~ (0.002243) CREATE TABLE "quotes" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)
36 ~ (0.000047) PRAGMA table_info("billings")
37 ~ (0.004413) CREATE TABLE "billings" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)
38 ~ (0.000022) PRAGMA table_info("billing_quotes")
39 ~ (0.002807) CREATE TABLE "billing_quotes" ("quote_id" INTEGER NOT NULL, "billing_id" INTEGER NOT NULL, PRIMARY KEY("quote_id", "billing_id"))
40#<DataMapper::Model::DescendantSet:0x10165a778 @ancestors=nil, @descendants=[Quote, Billing, BillingQuote]>