Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "lib/dm-core"
- DataMapper::Logger.new(STDOUT, :debug)
- DataMapper.setup(:default, 'sqlite3::memory:')
- class Profile
- include DataMapper::Resource
- property :id, Serial
- has n, :photos
- end
- class Photo
- include DataMapper::Resource
- property :id, Serial
- property :url, String
- belongs_to :profile
- end
- DataMapper.auto_migrate!
- profile1 = Profile.create
- profile1.photos.create(:url => 'http://example.com/photo')
- profile2 = Profile.create
- #profile2.photos.create(:url => 'http://example.com/test')
- puts '-' * 80
- Profile.all.each do |profile|
- puts "Profile #{profile.id}"
- profile.photos.inspect
- p profile.photos[0].url unless profile.photos.empty?
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement