jjabba
Where should I put my `def changeset` code when using Phoenix 1.4 and Contexts?
I’m working on an App using phoenix 1.4. Im trying to understand in which file to define my Ecto changesets. This is my particular scenario:
Under the ‘Domain’ context im creating entities and actors. These two Ecto schemas are defined in:
lib/myapp/domain/entity.ex & lib/myapp/domain/actor.ex.
My context related business logic lives in lib/my_app/domain/domain.ex.
I read this blog post a while back and to the best of my understanding it suggests to keep schemas clean and free of anything but the schema definitions, and favor putting any changeset definitions in the context (read the ‘Schemas are not models’ section of the blogpost’).
What is the most recent take on this, where should my changeset definitions for entity and actor go?
Marked As Solved
Also Liked
al2o3cr
FWIW, phx.gen.schema includes import Ecto.Changeset as part of every generated schema file. I’d consider that a strong endorsement from the framework for putting changeset functions in schemas ![]()
dimitarvp
Don’t get too hung up on how other people organize their projects. Find a way that looks intuitive to you and your team. The most important metric should be this one:
“How do I organize the project so that if I get a 3 months of vacation I’ll be able to decipher what I did immediately after coming back?”
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








