Advertisement
Guest User

Untitled

a guest
Jan 5th, 2009
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.72 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require "lib/dm-core"
  4.  
  5. DataMapper::Logger.new(STDOUT, :debug)
  6. DataMapper.setup(:default, 'sqlite3::memory:')
  7.  
  8. class Profile
  9.   include DataMapper::Resource
  10.  
  11.   property :id, Serial
  12.  
  13.   has n, :photos
  14. end
  15.  
  16. class Photo
  17.   include DataMapper::Resource
  18.  
  19.   property :id, Serial
  20.   property :url, String
  21.  
  22.   belongs_to :profile
  23. end
  24.  
  25.  
  26. DataMapper.auto_migrate!
  27.  
  28. profile1 = Profile.create
  29. profile1.photos.create(:url => 'http://example.com/photo')
  30.  
  31. profile2 = Profile.create
  32. #profile2.photos.create(:url => 'http://example.com/test')
  33.  
  34. puts '-' * 80
  35.  
  36. Profile.all.each do |profile|
  37.   puts "Profile #{profile.id}"
  38.   profile.photos.inspect
  39.   p profile.photos[0].url unless profile.photos.empty?
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement