trailblazer / roar-jsonapi

JSON API support for Roar.
http://trailblazer.to/gems/roar/jsonapi.html
MIT License
42 stars 18 forks source link

'links' in 'relationships' only printing last item in collection #5

Closed myabc closed 7 years ago

myabc commented 7 years ago

From @jtzero on July 20, 2016 0:15

  has_many :stores do
      type :stores

      property :id

      link :self do
        "http://localhost:3000/stores/#{represented.id}"
      end
    end

produces

"relationships"=>
   {"stores"=>
      {"data"=>[
          {"type"=>"stores", "id"=>"1"}, 
          {"type"=>"stores", "id"=>"2"}, 
          {"type"=>"stores", "id"=>"3"}
        ], 
        "links"=>{"self"=>"http://localhost:3000/stores/3"}
      }
   },
   "links"=>{"self"=>"://localhost:3000/retailers/9"}},
   "included"=>
     [
       {"type"=>"stores", "id"=>"1", "links"=>{"self"=>"http://localhost:3000/stores/1"}},
       {"type"=>"stores", "id"=>"2", "links"=>{"self"=>"http://localhost:3000/stores/2"}},
       {"type"=>"stores", "id"=>"3", "links"=>{"self"=>"http://localhost:3000/stores/3"}}
     ]
   }

the links are correct in the "included" but the one in "stores" is incorrect,and changing the self link in has_many changes all the ones in the 'included'. How do I change the one in stores?

Copied from original issue: trailblazer/roar#194

myabc commented 7 years ago

Reference: http://jsonapi.org/format/#document-resource-object-relationships

myabc commented 7 years ago

@jtzero I'm not sure if this issue is still relevant for you, but if it is, I'd appreciate feedback on this fix.