def MyApp.User do use MyApp.Web, :model schema "users" do field :first_name, :string field :last_name, :string field :preferences, :map end end
The problem is that preferences are different for each application that uses the users table. For example, mobile app A would want to store some mobile preference settings, while mobile app B would like to store its own settings. The user table is common to both. How do we model this?
One solution that comes to mind each mobile app would have its own structured data so changesets can be created. For example,
def MobileAppA do embedded_schema do ....copy all fields of MyApp.User schema over here again field :pref1, :string field :pref2, :string end end
Now do validations on this schema and if everything passes, write to the DB. Do the same for mobileAppB.
However, the user schema fields are copied over and over again into each embedded schema.
To solve the repetition problem, we could define a macro just for the fields and use that macro everywhere we need to have those fields. Is this the best way? Any better way of doing this? This has got to be a common problem I would think. Wondering how others are approaching this problem. Thanks in advance!