-
Notifications
You must be signed in to change notification settings - Fork 76
Closed
Labels
Description
Potential Issue
Currently it seems a view
is required to process any type of relationship.
ticket_view.ex
def relationships, do: [ticket_categories: MyProject.TicketCategoryView]
Right now, the below is needed because encode_data is called recursively through all the relationships and asks for each relationships view
.
ticket_category_view.ex
def relationships, do: [category: MyProject.CategoryView, ticket: MyProject.TicketView]
example payload
{
"relationships": {
"ticket-categories": {
"data": [{"id": "1234", "type": "ticket-category"}]
}
}
}
Brainstorming a solution
Since I'm most likely missing something, the first step for me would be to understand the need for a relationship's view
. In this case, it seems what might be ok to do is something like.
[ticket_categories: %{type: "ticket-category", field: "ticket_category_id"}]
Then one option during serialization of the data would have the lib do Map.get(ticket_data, field)
to get the id
for the relationship instead of recursively moving down the relationship tree.
Would appreciate some thoughts. I would love to open a PR!