Cannot declare has_many with primitive type #2

jnunemaker opened this Issue Apr 16, 2009 · 3 comments


None yet
4 participants

jnunemaker commented Apr 16, 2009

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


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'

vicentereig referenced this issue in vicentereig/happymapper Feb 7, 2012

Merge pull request #2 from JamesFerguson/master
Add an element ... :attributes => {...} example to

elorenzo1138 referenced this issue in elorenzo1138/happymapper Jun 1, 2012


ghost commented Jul 24, 2012


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 Jun 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment