Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

has_one mapping #27

Closed
ready4god2513 opened this Issue · 4 comments

2 participants

@ready4god2513

Given the following xml-

<?xml version="1.0" encoding="UTF-8"?>
<stories type="array">
  <story>
    <id type="integer">46499703</id>
    <project_id type="integer">784123</project_id>
    <story_type>feature</story_type>
    <url>http://www.pivotaltracker.com/story/show/46499703</url>
    <estimate type="float">1</estimate>
    <current_state>unstarted</current_state>
    <description>Sed et nisi sit amet leo tempus pulvinar nec vel magna. Pellentesque arcu metus, iaculis eget sollicitudin sit amet, scelerisque ut quam. Nullam mollis ligula at massa viverra luctus. Nulla non erat id arcu feugiat feugiat quis eget augue. Donec vestibulum pretium mi non porttitor. Nulla dapibus gravida mauris vel posuere. Sed dictum ultricies tellus vel venenatis.

&#402;&#172;&#729;&#8706;&#730;&#223;&#8710;&#729;&#402;</description>
    <name>Just a little test</name>
    <owned_by>
      <person>
        <id type="integer">126384</id>
        <name>Brandon Hansen</name>
        <initials>BH</initials>
      </person>
    </owned_by>
    <requested_by>
      <person>
        <id type="integer">1233535</id>
        <name>Chris Gratigny</name>
        <initials>CG</initials>
      </person>
    </requested_by>
    <created_at type="datetime">2013/03/19 21:25:26 UTC</created_at>
    <updated_at type="datetime">2013/03/19 21:33:26 UTC</updated_at>
    <labels>123,testing,&#8710;&#730;&#730;&#8706;&#229;&#402;</labels>
    <comments type="array">
      <comment>
        <id type="integer">39331775</id>
        <text>Adding some comments here</text>
        <author>
          <person>
            <id type="integer">126384</id>
            <name>Brandon Hansen</name>
            <initials>BH</initials>
          </person>
        </author>
        <created_at type="datetime">2013/03/19 21:25:27 UTC</created_at>
      </comment>
      <comment>
        <id type="integer">39331777</id>
        <text>And a picture</text>
        <author>
          <person>
            <id type="integer">126384</id>
            <name>Brandon Hansen</name>
            <initials>BH</initials>
          </person>
        </author>
        <created_at type="datetime">2013/03/19 21:25:27 UTC</created_at>
      </comment>
    </comments>
    <attachments type="array">
      <attachment>
        <id type="integer">17148567</id>
        <filename>Screen_Shot_2013-03-19_at_12.01.09_PM.png</filename>
        <uploaded_by>
          <person>
            <id type="integer">126384</id>
            <name>Brandon Hansen</name>
            <initials>BH</initials>
          </person>
        </uploaded_by>
        <s3_resource>
          <url>https://s3.amazonaws.com/prod.tracker2/resource/17148567/Screen_Shot_2013-03-19_at_12.01.09_PM.png?AWSAccessKeyId=AKIAIKWOAN6H4H3QMJ6Q&amp;Expires=1363730677&amp;Signature=5ZiyAer7jZ9eHqZXcxX%2FNKJYahU%3D</url>
          <expires type="datetime">2013/03/19 22:04:37 UTC</expires>
        </s3_resource>
        <uploaded_at type="datetime">2013/03/19 21:25:21 UTC</uploaded_at>
        <url>https://www.pivotaltracker.com/resource/download/17148567</url>
      </attachment>
    </attachments>
    <tasks type="array">
      <task>
        <id type="integer">13346287</id>
        <description>Get</description>
        <position type="integer">1</position>
        <complete type="boolean">false</complete>
        <created_at type="datetime">2013/03/19 21:25:27 UTC</created_at>
      </task>
      <task>
        <id type="integer">13346289</id>
        <description>It</description>
        <position type="integer">2</position>
        <complete type="boolean">false</complete>
        <created_at type="datetime">2013/03/19 21:25:27 UTC</created_at>
      </task>
      <task>
        <id type="integer">13346291</id>
        <description>Done</description>
        <position type="integer">3</position>
        <complete type="boolean">true</complete>
        <created_at type="datetime">2013/03/19 21:25:27 UTC</created_at>
      </task>
    </tasks>
  </story>
</stories>

And the following mappings-

class Story
  include HappyMapper

  element :id, Integer
  element :project_id, Integer
  element :story_type, String
  element :url, String
  element :estimate, Float
  element :current_state, String
  element :description, String
  element :name, String
  element :created_at, DateTime
  element :updated_at, DateTime
  element :accepted_at, DateTime
  element :labels, String
  has_one :owned_by, Person
  has_one :requested_by, Person
  has_many :attachments, Attachment
  has_many :comments, Comment

end

class Person
  include HappyMapper

  element :id, Integer, deep: true
  element :email, String, deep: true
  element :name, String, deep: true
  element :initials, String, deep: true
end

Both :owned_by, Person, and :requested_by, Person return the person mapped under owned_by. If I switch the order of owned_by and requested_by in the xml, the requested_by will be returned for both instances of Person, which makes me think that we have an issue with the xpath.

What am I missing here?

@ready4god2513

The app/gem that is using this can be checked out here if you want to see the failing specs.

@jnunemaker
Owner

Odd. Definitely sounds like a bug. Honestly, I haven't worked on the project in forever. Happy to merge a tested pull request though.

@ready4god2513

Ok, thanks!

@jnunemaker
Owner

Closing due to staleness and the fact that the project is currently not being maintained. There is a maintained fork https://github.com/dam5s/happymapper.

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