Cannot declare has_many with primitive type #2

Closed
jnunemaker opened this Issue Apr 16, 2009 · 3 comments

Comments

Projects
None yet
4 participants
Owner

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

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

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

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 README.md

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

@ghost

ghost commented Jul 24, 2012

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

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