overture8
How to approach converting camelCase to snake_case field names
Hi folks,
I am hooking Phoenix up to an existing database that (unfortunately) has camelCase field names. I was wondering has anyone had any experience with this? I know that you can make Ecto work with camelCase field names but, ideally, I’d like to convert/translate the field names to snake_case when they are read from the database. It this possible? Or is it a bad idea?
Thanks,
Phil
Marked As Solved
zimt28
Even though I can’t tell you how to do this right now, Ecto might support aliases in the future: Allow schema :field to have an alias · Issue #1892 · elixir-ecto/ecto · GitHub
Also Liked
gon782
Macro.underscore/1 will turn camelCase and PascalCase into snake_case. I don’t know if you’re supposed to use something else, but that’s the one I usually use if I need to.
iex> Macro.underscore "hejHopp"
"hej_hopp"
It also works with modules, etc.
iex> Macro.underscore HejHopp
"hej_hopp"
jackalcooper
Looking forward to this feature. Very useful when I’m writing elixir app for a legacy database created by Rails.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









