Created
January 2, 2009 15:44
-
-
Save czottmann/42573 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
# 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 | |
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
<!-- ... --> | |
<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