You’d then set up a separate schema for LiveviewChat.Admin.Message
or LiveviewChat.Statistics.Message
.
In Ecto, schemas are less tightly coupled to database tables than other ORMs like Rails’s ActiveRecord where one record generally gets mapped to one object. This separation is a bit more verbose but offers much more control by letting us explicitly set how objects are mapped for a given context based on how it will be used in that given context.
So if for privacy reasons, the statistics context should not analyze the message body, Statistics.Message
schema could simply not map the message body and instead map only the fields relevant for analytics. Another example from an older version of the docs if memory serves was a users table that maps to Accounts.User
and Blog.Author
.