Self referencing many to many

Ok, now I understand, You want a partner relationship AND You want to keep the hierarchy, between from and to. I can see now why my solution bugs You :wink:

In that case, if it was for me, I would add a custom query to load partners that would use an or statement.
This way I could query partners without losing from -> to information.

1 Like

Its good at least i conveyed the point across.
How can we add a complex query?

There is another solution, You can add metadata to the join table, eg: direction: [from/to]

Then create 2 suborganizations keys, one with from, the other with to.
This way You can keep the association way of doing, without needing special queries. And keep the from/to info.

Otherwise, and not in the same context, I used that kind of query

where([g], g.black_id == ^player.id or g.white_id == ^player.id)

The context is a game with 2 players, and I wanted to get all games for a given player, as black or white. I used this query with an or statement.

Ecto should have this feature

I am not sure it is Ecto related. Back in the old rails days and active records, in the end, I would get all partners by adding partners_from and partners_to.

this guy probably wants the same thing: