How to make Many-To-Many Relations with Elixir/Ecto

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 9

  • @envueltoenplastico
    @envueltoenplastico 7 місяців тому +1

    Native English speaker here - no need to apologise, your English was great! Nice clear explanation. I'm generally comfortable with Ecto fairly I've struggled to get comfortable with with many-to-many associations and how to handle them in an idiomatic way. I use the way you suggested so I am glad to see that!
    That said, I think I was incorrectly labouring under the assumption that there's some more automatic (magical?) way to do it but I am starting to accept that this is not the case :) And you rightly point out that the approach might be problematic when dealing with large amounts of associations, which is of course interesting and I wonder what would be a good approach in the (rare) cases where that's important.
    Anyway, very enjoyable video - thanks!

    • @BrunoRibeiroDev
      @BrunoRibeiroDev  6 місяців тому

      Thank you! I really appreciate it! Now, moving on to your question, if you have a large amount of associations, I would suggest directly inserting them into the table. In the end, Ecto acts as a wrapper to simplify the developer's life, but we still have access to the "user_course" table. Therefore, we can use the "insert_all" function to insert the associations directly into the table

  • @ruthaosolhosdopai8962
    @ruthaosolhosdopai8962 2 роки тому +1

    Gostei muito da apresentação!! Vou aparecer mais vezes por aqui.... parabéns 👌

  • @skryonline5825
    @skryonline5825 Рік тому

    Mucha gracias, Bruno! Thanks bro for nice explanation

  • @nmarcolin
    @nmarcolin 2 роки тому +1

    Olha só, que arraso!

  • @jazzgarcha9929
    @jazzgarcha9929 2 роки тому

    @Bruno, thanks for this video. Great job. I have request on how to query a many-to-many db data. Say I have 3 tables (users, wishes, user_likes(join_table), I want query a list of all wishes, and includes the likes. (I have this part.) but I want to check if current_user has liked the wish Is that possible?

    • @BrunoRibeiroDev
      @BrunoRibeiroDev  2 роки тому +1

      Hey! Jazz! Thanks man! I don't know if I understood perfectly you question, but I think that it is possible, and the query is gonna be something similar to this:
      from(w in Wishes, as: :wishes, select: w)
      |> join(ul in UserLikes, as: :user_likes, on ul.wishes_id == w.id
      |> where([user_likes: ul], ul.user_id == ^current_user.id

    • @jazzgarcha9929
      @jazzgarcha9929 2 роки тому

      @@BrunoRibeiroDev Sweet, thanks man! Keep posting videos.