Created
November 28, 2008 07:41
-
-
Save dkubb/29933 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
# 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