Mapping values in a Phoenix View
Closed this issue ยท 2 comments
Hello ๐ ,
I have a couple of doubts, both related to mapping. I am using the [Ja Phoenix View].(https://hexdocs.pm/ja_serializer/JaSerializer.PhoenixView.html)
-
The view is always displaying the
id
field. In my case this field is private and only used internally. Instead, we communicate with theuuid
field. I would like to use by default theuuid
field, and not overwrite the id in my controller before passing it to the view. Any ideas on how to do this? -
I smaller issue, I would like to add some fields in the view that are not directly related to the database record. How can I add a field in the view without specifying the value in the controller? Some keys are renamed in the view vs the database record.
Thanks for your time!
@hylkealons check out the JaSerializer.Serializer documentation, specifically the attributes/2 and id/2 callbacks - https://hexdocs.pm/ja_serializer/JaSerializer.Serializer.html#c:attributes/2
https://hexdocs.pm/ja_serializer/JaSerializer.Serializer.html#c:id/2
I think those should address both your questions.
thanks @beerlington for the quick and useful reply, works like a charm!