How to reload model after having inserted a list of child models in it?

Suppose, I have an Article and Comment.

a1 = Repo.get(Article, 123)
cm1 = a1.comments

cm2 = get_new_comments()
Enum.each(fn c ->
  # insert comment to Article a1


# ??? how to reload a1 without additional overhead?

I already have loaded a1 and I have a list of new comments. After inserting the new comments, how can I make a1 change its state such that it becomes aware of the new comments.

I could do that by callling Repo.get(Article, 123) again. My question, however, how to avoid this additional db request?

You could always just put the things you inserted onto the a1 structure itself in whatever form you want. :slight_smile:

  comments = cm2 # or process it as you need