f0rest8
Hi everyone,
Just wanted to say that the new Self-referencing many to many guide is now up on the official Hex docs (at least I just noticed
). If anyone is thinking about (or struggling with) implementing associations that self-reference each other, then I encourage you to check out this guide.
This latest guide is inspired from my own utilization of this association strategy in an upcoming social connection web app built with Elixir and Phoenix — it was forged in fire, so to speak. So, I hope it helps anyone else struggling to implement a similar strategy in their own applications. ![]()
Trending in Guides/Tuts
# ~/src/livebook/.iex.exs
System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] )
Because Livebook requires a unique passcode on ...
New
Other Trending Topics
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cs44
I’m following your guide, which is great - thanks, but am left wondering how you might handle adding multiple records vs a single call to the
Relationshipchangeset.f0rest8
I would use Ecto.Multi, something like:
If I’m not mistaken, what’s great about it is that you don’t really have to do anything tricky. I haven’t tested this but I think this is a good guide on
Ecto.Multifrom Elixir School.** Forgot to include
Repo.transaction()H12
Just came across this guide and the following one on polymorphism – both great! However I’m having a little trouble puzzling out the appropriate way to combine the two concepts…
For example, if I wanted to model discrete types of relationships between two people (e.g. coworkers, friends, or parent/child), what would be a good way to go about it?
My first instinct would be to have a single table with a “relationship_type” field, but it seems like the proper “Ecto” way might be to create multiple joins tables for each relationship type?
Curious to hear your thoughts.
f0rest8
On one of my early design choices for an earlier version of Metamorphic I used a separate
relationship_typethat was associated to arelationshipthrough ahas_many/belongs_toassociation.Then, in another iteration, I used an
Ecto.Enumfield oftypeon therelationshiptable and got rid of therelationship_typetable:In the latest design choice, for the latest version of Metamorphic, I dropped the
many_to_manyassociation style and enum and I simply used alabelfield in theuser_connectiontable to change the “type” of relationship to be simpler and more like a “tag” that people can update to their liking and theuser_connectiontook on more similar a role as the first version’srelationshiptable.I think it really depends on what you’re going for and how you want to structure everything for your particularly use case and future design choices when developing further… if/when I do it again, I would probably go with the
many_to_manyassociation for users and then the “label” style for the field.So, for your example… questions might be:
I think you might do something like the
personexample for users…This would give you a separate table
relationshipswith aRelationshipstruct where you can have everything related to a relationship there. Then, users are “connected” to each other through thatrelationshiptable and it simply has anEcto.Enumfield to designate the type of relationship.These are my initial thoughts. I feel like it really just depends…