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!
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
@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?
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
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!
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
Gostei muito da apresentação!! Vou aparecer mais vezes por aqui.... parabéns 👌
Mucha gracias, Bruno! Thanks bro for nice explanation
Olha só, que arraso!
@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?
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
@@BrunoRibeiroDev Sweet, thanks man! Keep posting videos.