Skip to content

Instantly share code, notes, and snippets.

@dkubb
Created November 28, 2008 07:41
Show Gist options
  • Save dkubb/29933 to your computer and use it in GitHub Desktop.
Save dkubb/29933 to your computer and use it in GitHub Desktop.
# Embedded Value for DataMapper (http://martinfowler.com/eaaCatalog/embeddedValue.html)
class Address
include DataMapper::EmbeddedValue
property :street, String
property :location, String
property :region, String
property :country, String
end
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
property :address, Address # Embedded Value
end
address = Address.new(
:street => '123 Main Street',
:location => 'Anytown',
:region => 'BC',
:country => 'Canada'
)
person = Person.new(
:name => 'John Doe',
:address => address
)
person.address_street # => "123 Main Street"
person.address_location # => "Anytown"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment