vt-elixir / ja_serializer

JSONAPI.org Serialization in Elixir.
Other
640 stars 148 forks source link

Association links instead of data #312

Closed strzibny closed 5 years ago

strzibny commented 5 years ago

Hello all,

wondering if it's possible to specify the association ID in the links section.

E.g.

has_one :author,
    serializer: PersonSerializer,
    links: [
      related: "/people/:id"
    ]

will use the original model as :id instead of the author ID :(.

Is it possible to reference :author_id instead to link to the resource?

Also secondly, I would like to omit the data attribute for the relationship. Is this possible?

alanpeabody commented 5 years ago

Yes.

https://hexdocs.pm/ja_serializer/0.14.0/JaSerializer.DSL.html#has_many/2

To use :author_id just define author_id/2 in your module that returns the correct value.

To omit the data do not include the serializer option.

strzibny commented 5 years ago

Perfect! Thanks a ton for your reply.