I’m building an application where I need to store how many people in
certain age groups live in a home. For example, the paper form looks like this. Where the user would
write in number next to the age group.
I’m unsure of how to persist this data. I could do something like the following but it seems clunky.
Can anyone suggest a better way to do this?
defmodule Pantry.Household do
schema "household_member_age_groups" do
field :0_5, integer
field :6-12, integer
field :13_18, integer
field :address, string
end
defmodule Pantry.HouseholdMember do
use Ecto.Schema
alias Pantry.Address
schema "household_members" do
belongs_to :address, Address
field :age, :integer
end
end
defmodule Pantry.Address do
use Ecto.Schema
alias Pantry.HouseholdMember
schema "addresses" do
has_many :members, HouseholdMember
field :data, :string
end
end
Yes, that is a solution thank you. I need to present the age groups in the UI for the user to choose from. The age group data has the shape of a map to me. I feel myself trying to couple the UI with the data layer, which I know is wrong, but easier to do at my level of skill.