     res_model = resource.__struct__
     case res_model.__schema__(:association, field) do
       %{through: [first, second]} -> 
-        {:ok, {res_model.__schema__(:association, first).assoc, second}}
+        {:ok, {res_model.__schema__(:association, first).related, second}}
       _ -> 
         {:error, :notfound}
     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}"

  def get_assoc_model(resource, field) do
    case get_assoc_join_model(resource, field) do
      {:ok, {assoc, second}} -> 
        {assoc.__schema__(:association, second).related, assoc}
      error ->  
        error
    end
