jjabba

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

jjabba

jjabba

Thanks!
I’ve eyed through the docs linked by @Eiji, and based on that and the way the phx.gen.schema behaves I have decided to put my changeset def in the schema files with @doc false, and use specialized functions in the context as a gateway to access them.

Also Liked

al2o3cr

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 :slight_smile:

dimitarvp

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?”

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement