HerrBertling

HerrBertling

Hey all!

I‘m currently learning Phoenix and Elixir. My day job is working on the frontend side of things with React.

For fun, I started building a project management app for craftsmen. Different companies should use it. They‘d have projects, a calendar, overview of the latest changes,…

There’s a nested data structure that I have on the project detail page and I‘d love to get some advice on how to „think“ of this in a Phoenix-Elixir-way.

Each project has phases, each phase has tasks and each task can have appointments. I‘ve got all of these in separate data tables (another thing I never touched - data modeling on the db level :sweat_smile:) which seems to be the correct way to do it, quite a few belongs_to in there as well.

When I think about this from the UI side of things, my hunch is to add a form for „add task“ as a LiveComponent. I could of course do all of this at once in a single LiveView and render some nested data structure with different events for different forms. Or could I? Coming from Remix, I‘m used to thinking in nested routes, but that‘s unfortunately not a thing in Phoenix from what I understood so far.

Since I have almost no experience with all of this besides a few tutorials, I would love to get some feedback on how people handle these scenarios. Nested data structures have to be common scenarios, no?

Appreciate any thoughts and hints on this.

Showing Posts 1 to 4

BartOtten

BartOtten

Welcome at the forum, @HerrBertling

I am not exactly sure what you are looking for, but I’ll just throw these links in the mix. Maybe they are what you were looking for, maybe not and then we have narrowed down the problem space.

Please let me know if these links helped you.

BartOtten

BartOtten

Are there any Phoenix devs out there who feel the same? I myself haven’t done Phoenix projects were I missed nested routes but maybe there is demand…then I might write a proof of concept plugin for Routex.

josevalim

josevalim

Creator of Elixir

Welcome @HerrBertling! Generally speaking, you may read data as nested but most updates happen within the data directly.

For example, if projects has phases, phases has tasks, and task have appointments, and you are showing them all on the same page, then you would likely load all of the data as nested, using Ecto’s preloads. On the other hand, if you only show appointments once you are seeing a task page, which is potentially a separate LiveView, you are likely only loading that particular task and its appointments.

When it comes to adding a new task, you most likely send only the “phase_id” to the server alongside the task parameters. Then when you receive the event, you validate the user can indeed edit and add tasks to that phase, and then you insert the task with its relevant phase_id to the database. The insertion does not need to go through the nesting.

HerrBertling

HerrBertling OP

I think that was the general mode of thinking I was looking for. I’m maybe too used to the “a route/subroute determines the data loaded/mutated” by Remix right now :smile:

Since all of this stuff should happen within the same view, I feel like a LiveComponent per form is the correct abstraction. I can encapsulate the logic there and handle any events in there as well.

I could have imagined loading everything in the LiveView and passing it down into the components. Handling the different changesets and events in the overall LiveView seems a bit cumbersome and convoluted, though. Anyways. I wasn’t aware of nested preloads until now. That will come in handy at some point!

Is it a “good thing”™ to preload everything, pass the data to the LiveComponent and then update that data from there? How would data revalidation then work? Changing the state of a task might affect the state of the whole phase (finish the last task => phase is completed), so I’d have to somehow revalidate all data to make sure the UI is not out of sync.

Oh, and @BartOtten, if the general idea is to mutate data directly “where you are”, I don’t need nested routes.

I guess I’m trying to carry over too many mental models from working in react-router/Remix that don’t really fit the mental models Phoenix uses. Just takes some time to adjust to that, I guess, and I’m trying to benefit from all of your experience :sweat_smile:

Thanks for the hints so far!

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews