public
Created

Book, User, Address

  • Download Gist
book_user_address.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
class Book
include DataMapper::Resource
 
property :id, Serial
property :title, String
property :author, String
property :price, Decimal
end
 
class User
include DataMapper::Resource
 
property :id, Serial
property :name, String
 
property :address_country, String
property :address_city, String
 
validates_presence_of :name
 
def address= address
self.address_country = address.country
self.address_city = address.city
end
 
def address
Address.new(address_country, address_city)
end
end
 
class Address < Struct.new(:country, :city)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.