We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
How to Alias Field Names in Ecto for Better Domain Modeling
255
clicks
Source: elixirstreams.com
When working with existing databases in Elixir, using Ecto schemas can sometimes lead to working with legacy or poorly named columns. The article explains a feature of Ecto that allows developers to define a more suitable field name in the schema while mapping it to the original column name in the database. This is done using the `field` function in schemas, specifying a new name and using the `source:` option to point to the original column name. For example, a column named 'checked' can be aliased to 'completed' within the application, making the code cleaner and more expressive while Ecto handles the mapping to the actual database column transparently during queries.
Related posts
© HashMerge 2024