     # 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 
+    field1 = res_model.__schema__(:association, join_table_name).related_key
+    field2 = new_model.__struct__.__schema__(:association, join_table_name).related_key 
 
     "from c in #{join_model}, where: c.#{field1} == #{resource.id} and " <>
       "c.#{field2} == #{new_model.id}"

    # 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}
    ])
  end


      %{through: [first, _]} -> 
        # assoc_model =  res_model.__schema__(:association, first).assoc_key
        {:ok, {
          res_model.__schema__(:association, first).related_key, 
          res_model.__schema__(:association, first).related.related_key, 
        }}
      _ -> 
        {:error, :notfound}
