Skip to content

Instantly share code, notes, and snippets.

@czottmann
Created January 2, 2009 15:44
Show Gist options
  • Save czottmann/42573 to your computer and use it in GitHub Desktop.
Save czottmann/42573 to your computer and use it in GitHub Desktop.
# The problem is that the Person object currently has two sub-objects:
# PersonFirstname and PersonLastname, and both have a @value attribute, which
# is suboptimal.
# Is there a way to end up with a Person object that has both @firstname and
# @lastname, without extraneous child objects?
class PersonFirstname
include HappyMapper
tag "firstname"
attribute :value, String
end
class PersonLastname
include HappyMapper
tag "lastname"
attribute :value, String
end
class Person
include HappyMapper
tag "person"
has_one :firstname, PersonFirstname
has_one :lastname, PersonLastname
end
<!-- ... -->
<people>
<person>
<firstname value="john"/>
<lastname value="doe"/>
</person>
<person>
<firstname value="john"/>
<lastname value="doe"/>
</person>
</people>
<!-- ... -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment