Skip to content

Type ignored on relationship definition #342

@elvanja

Description

@elvanja

Hi!

So I am trying to reuse an existing serializer for a relation that has a different (include) name/type. For example:

defmodule AuthorView do
  has_many :articles,
    serializer: ArticleView,
    link: :articles_url
  
  has_one :pinned_article,
    serializer: ArticleView,
    link: :pinned_article_url,
    type: :pinned_article
end

defmodule ArticleView do
end

But, the type: :pinned_article is ignored. Relation always gets rendered as:

"pinned-article" => %{
 "data" => %{
   "id" => payment.id,
   "type" => "article"
 }
}

And the same for included relation/object as well. The type remains article, instead of pinned-article.
The main reason for reusing is to not have to repeat the additional logic ArticleView, e.g. how it sets the self URL, some attributes etc.

Any ideas on how to solve this one?
Thank you 🙇🏼

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