Inconsistency in attribute and relationship functions
lasseebert opened this issue · 1 comments
In a view, one can specify a custom attribute in two ways:
attributes [:foo]
def foo(model, _conn), do: model.bar
# OR:
def foo(model), do: model.bar
For relationships only the first way works:
has_one(:foo, include: true, serializer: SomeView)
def foo(model, _conn), do: model.bar
This inconsistency caught me and I spend some time figuring out what was wrong. (Especially because the default behaviour just defaults to nil
if a function or attribute is not found).
Is this intended? Otherwise I will happily make a PR making it consistent.
I don't believe that's intentional and I wasn't even aware that the def foo(model), do: model.bar
version worked. It looks like that's happening here https://github.com/vt-elixir/ja_serializer/blob/master/lib/ja_serializer/dsl.ex#L242-L243
If possible, I think it makes sense to support the single argument relationship so it's consistent. I would be happy to accept a PR for that. Thanks!