     # get the join model atom
     join_table_name = get_assoc_join_name(resource, Utils.to_atom(has_many_atom))
     struct(join_model.__struct__, [
-      {res_model.__schema__(:association, join_table_name).assoc_key, resource.id},
-      {new_model.__struct__.__schema__(:association, join_table_name).assoc_key, new_model.id}
+      {res_model.__schema__(:association, join_table_name).related_key, resource.id},
+      {new_model.__struct__.__schema__(:association, join_table_name).related_key, new_model.id}
     ])
   end
 

    # get the join model atom
    join_table_name = get_assoc_join_name(resource, Utils.to_atom(has_many_atom))

    field1 = res_model.__schema__(:association, join_table_name).assoc_key
    field2 = new_model.__struct__.__schema__(:association, join_table_name).assoc_key 

    "from c in #{join_model}, where: c.#{field1} == #{resource.id} and " <>
      "c.#{field2} == #{new_model.id}"

  end

  def update(%Changeset{} = changeset) do
    {:ok, resource} = repo.update changeset.changeset
    
    for {cs, fun} <- changeset.dependents do
      if cs do
