Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Cannot declare has_many with primitive type #2

jnunemaker opened this Issue · 3 comments

4 participants


I have the following mapping for the attached xml:

module FamilySearch class AlternateIds include HappyMapper tag ‘alternateIds’ has_many :ids, String, :tag => ‘id’ end class Information include HappyMapper has_one :alternateIds, AlternateIds end class Person include HappyMapper attribute :version, String attribute :modified, Time attribute :id, String has_one :information, Information end class Persons include HappyMapper has_many :person, Person end class FamilyTree include HappyMapper tag ‘familytree’ attribute :version, String attribute :status_message, String, :tag => ‘statusMessage’ attribute :status_code, String, :tag => ‘statusCode’ has_one :persons, Persons end end

Notice the AlternateIds class declares a has_many with type String, which should assign ids as a collection of Strings. However, ids ends up being a String of the first object.

I have a failing spec in my fork that represents this situation:


Another failing spec here:

I've actually fixed this in my fork (, but I've also switched over from using libxml directly to using nokogiri instead. You probably need to change find_first to find in line 122 item.rb, and then do something similar to this commit:



I went to fix this and discovered it already was! The syntax confused me a bit (having to specify the singular tag), but I'll leave it be.

has_many :answers, String, :tag => 'answer'



I think I have similar issue, I have following mapping:

class Customer
  include HappyMapper
  has_many :languages, String, :tag => 'Languages'

and following xml


Any chance to map something like this to an array of strings:

@languages=["en", "pl"]

At the moment I get following structure:

@languages=["\n    en\n    pl\n  "]


@jnunemaker jnunemaker closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.