Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.
This repository was archived by the owner on Feb 25, 2022. It is now read-only.

Assumptions of return JSON format lead to incorrect attribute associations #10

@coneybeare

Description

@coneybeare

I have a JSON api which returns a root key when a collection is returned. Something like:

{ "foobars": [ {"id":1, "name":"baz"}, {"id":2, "name":"zab"} ] }

When remotely parses the remote object, it attaches the root "foobars" key as an attribute on the model. This means that if I have a class in my local project named Grass...

class Grass
  has_many_remote :foobars
end

class Foobar < Remotely::Model
end

... if I want to iterate over the grass's foobars, I have to do this

    @grass.foobars.foobars.each

... instead of ...

    @grass.foobars.each

Proposed solution
When parsing a has_many_remote response, if the root key of the returned json equals the name of the association, attach the returned json's array value for said key instead of the key. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions