I need coaching in Ecto/Elixir

Is there somebody who could coach me over Skype on Ecto and help me solve a quite trivial problem: Build a tree-like structure of entities, based on a table that references itself. I am ready to pay, if it is a reasonable amount of money.

I feel that either Ecto and Elixir are not the right tools for it, or I simply don’t have enough experience with these tools to figure it out on my own, just with books and tutorials. After about two months of struggling, I am ready to give up on Elixir. And I really don’t want to, because it looks like a neat tool.

Thank you and sorry if this kind of requests doesn’t belong here. I will understand removing it, if that’s the case.

2 Likes

So, I see that you wrote this thread a few days ago.

I’m far from a specialist, but maybe I could help. I’ve made something similar to this problem.

From your original post, I think the problem could be in your changesets. Usually all you need is to use put_assoc or cast_assoc and Ecto will build your associations in the database. Can you post them?

2 Likes

I replied to a similar question in another thread: Ecto preload for tag has_many tags

To summarise, asking “How to do this in ecto” is the wrong question. The right question is “How to do this in SQL”. Ecto, differently from ORMs (and that’s probably the important difference, not the fact that elixir doesn’t have objects), keeps close to the semantics of the underlying data storage and does not try to abstract it. This means that to use Ecto efficiently, one should understand the database.

2 Likes

Michal, thank you for your answer. Writing up a Postgres query that would load the tree data and make it work took me an hour. And I don’t agree that expressing a precise query for this is not possible: “WITH RECURSIVE” in Postgres or “START WITH … CONNECT BY” in Oracle are tools made exactly for this case.

What drives me nuts is how to build a tree of Ecto entities in memory, using put_assoc, given that I already have a 2D list of data from the DB (that was the easy part). I will try a couple more things and if they don’t work, I will post my code, as a reaction to rms.mrcs.

2 Likes

rms.mrcs, thanks for the answer. I was doing some research and this post on Stackoverflow helped me realize something:

Working with trees in a compulsory immutable environment will be pain in the ass no matter what. Building trees in Elixir is really hammering nails with a screwdriver. I will probably change the framework, since I don’t want to have to write 300 line module, just to build a simple tree. Thank you for your help though.

1 Like