5
votes

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
1
Can't you just rename the column?AbM
There are other legacy applications that access the same database -- so renaming the column isn't really a solution right now.sudobangbang

1 Answers

4
votes

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