vt-elixir / ja_serializer

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

Compilation error with 0.13 #296

Closed supercodepoet closed 5 years ago

supercodepoet commented 5 years ago

After upgrading to 0.13 from 0.12 my serializer views don't compile. I have a struct that has a label attribute:

defmodule FontawesomeWeb.Icons.Definitions.CategoryView do
  use FontawesomeWeb, :view
  use JaSerializer.PhoenixView

  location("/api/category-definitions")

  attributes([
    :id,
    :label
  ])
end

when trying to compile I get: imported Phoenix.HTML.Form.label/2 conflicts with local function

In Phoenix the :view has a use Phoenix.HTML which will import all the HTML functions for use in templates. This collision does not happen on v0.12.

Is there something I should do that I am missing?

beerlington commented 5 years ago

I'm pretty sure you're doing everything correct and it's just an unfortunate limitation right now in JaSerializer. For the time being you have two options:

  attributes([
    :id,
    :label_alias
  ])

def label_alias(model, _conn), do: model.label

or use the attributes/2 callback.

supercodepoet commented 5 years ago

excellent!!! That worked perfectly. Thanks for the help!