Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cannot declare has_many with primitive type #2

Closed
jnunemaker opened this Issue · 3 comments

4 participants

@jnunemaker
Owner

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: http://github.com/jimmyz/happymapper/commit/496365548e20a15707a46be9a756b1035301773e

@knaveofdiamonds

Another failing spec here: http://github.com/knaveofdiamonds/happymapper/commit/6635900aa35f2b414cd14c953f4b80107219a589

I've actually fixed this in my fork (http://github.com/knaveofdiamonds/happymapper/), 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: http://github.com/knaveofdiamonds/happymapper/commit/440fc5aef143f064d99f6f91d433e61cfd8058f2

HTH,
Roland

@danielmorrison

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'

@dedico

Hi,

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

class Customer
  include HappyMapper
  [...]
  has_many :languages, String, :tag => 'Languages'
end

and following xml

<Customer>
  <Languages>
    <Language>en</Language>
    <Language>pl</Language>
  </Languages>
</Customer>

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  "]

Thanks,
Marek

@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.