So I have a legacy database schema that I am trying to normalize with the help of Elixir (Phoenix) and Ecto. The column definitions work fine, but they are horribly names (hooray for technical debt).
Is there a way to alias a column name, i.e. "meetingName" becomes "meeting_name" when displaying and managing it through the generated api? I've looked through the Ecto documentation and can't seem to find it at all.
Example,
@primary_key {:meetingId, :integer, []}
@derive {Phoenix.Param, key: :meetingId}
schema "meeting" do
field :meetingName, :string
timestamps()
end
You can use the source
option as documented here. This lets you specify the database column that this field refers to. For example:
field :meeting_name, :string, source: :meetingName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With