-
-
Save anonymous/a081a83ea2c8d67cf5f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'data_mapper' | |
DataMapper::setup(:default, "sqlite3://#{File.expand_path('app.db')}") | |
module MyApp | |
class DB | |
class Page | |
include DataMapper::Resource | |
property :id, Serial, :key => true | |
has n, :photos | |
has 1, :main_photo, 'Photo' | |
end | |
end | |
end | |
module MyApp | |
class DB | |
class Photo | |
include DataMapper::Resource | |
property :id, Serial, :key => true | |
belongs_to :page | |
end | |
end | |
end | |
DataMapper.finalize | |
DataMapper.auto_upgrade! | |
puts "==> Page" | |
puts page = MyApp::DB::Page.create | |
puts "==> Photos" | |
3.times { puts MyApp::DB::Photo.create(:page => page) } | |
page = MyApp::DB::Page.get(1) | |
puts "==> Page Photos" | |
puts page.photos | |
# why does this get set? | |
puts "==> Page Main Photo" | |
puts page.main_photo | |
# this fails! | |
puts page.update(:main_photo => MyApp::DB::Photo.get(3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment