Best Way to Design Resources Properties

Hello. Firstly, this is a great community: friendly and responsive. Secondly, I have a question that, I hope, is not silly. Suppose I want to have a resource named Evals. In it, I want to have the attributes: description, and numeric, where each description corresponds to a specific numeric value. My questions are: 1. What would you recommend: making an attribute of type map, or separating the two parts of the map into 2 attributes? 2. If I use the map type for the attribute, does it make sense to specify that I want only one by saying one_of: Map.to_list(my_map)
5 Replies
ZachDaniel
ZachDaniel3y ago
Could you give me an example of what the data might look like?
%{
evals: [
%{numeric: 10, description: "description"},
...
]
}
%{
evals: [
%{numeric: 10, description: "description"},
...
]
}
Like that?
hassanshahin
hassanshahinOP3y ago
Yes, Sir
ZachDaniel
ZachDaniel3y ago
I'd suggest creating an "embedded resource" with the numeric and description attributes. Then, I'd suggest declaring your attribute like attribute :evals, {:array, YourEmbed}.
hassanshahin
hassanshahinOP3y ago
Aha. I'll try that. Thanks, Zack.

Did you find this page helpful?