Is it possible to update parent and nested (assoc) entity via one call in Repo?


#1

Is there any way to perform update in Repo simultaneosly on parent and nested entity?

When you have has_one relation like in docs http://hanamirb.org/guides/1.2/associations/has-one/
create operation for User + Avatar works this way

 def create_with_avatar(data)
    assoc(:avatar).create(data)
  end

is there a way to do update in similar way?
because calling

  def update_avatar(user, data)
    assoc(:avatar, user).update(data)
  end

would update only Avatar, but User is not updated (even if you provide correct nested Hash as data input like {username: "Yevhen", bio: "Cool", avatar: { url: "yevhen.jpg" }}).

Another question - is it possible to do somehow via raw ROM access (changeset or command)?