Fix $d < 0$, a fundamental quadratic discriminant and $n$ a positive integer. Suppose $Q$ is a primitive binary quadratic form of discriminant $d$. Let us define the following,
1. Representations of $n$ by $Q$: $R(Q, n) = \{ (x, y) \in \mathbb{Z}^2 |  Q(x, y) = n\}$
2. $Aut(Q)$ as the subgroup of $SL_2(\mathbb{Z})$ that fixes $Q$ under the usual action of $SL_2(\mathbb{Z})$ on binary quadratic forms.
3. $R(d, n) = \coprod_QR(Q, n)/Aut(Q)$ as $Q$ runs through a complete set of representatives for each class of properly equivalent forms. Typically, we may select the reduced forms.
4. $I(d, n) = \{I \textrm{ proper ideals of the ring of integers of } K \textrm{ of norm } n \}$ where $K = \mathbb{Q}[\sqrt{(d)}]$ the quadratic numberfield of discriminant $d$.
5. The Epstein zeta function for $Q$: $\zeta(s, Q) = \frac{1}{2} \sum_{(x, y) \neq (0, 0)}{(Q(x, y))}^{-s}$ for $\mathfrak{R}(s) > 1$ for $(x, y) \in \mathbb{Z}^2$
6. The Dirichlet zeta function for $K$: $\zeta(s, K) = \sum_{I}{Nm(I)}^{-s}$ for $\mathfrak{R}(s) > 1$ as $I$ runs through all the proper integer ideals of $K$.

As a fact I know that when $d < -4$, $\sum_{[Q]}\zeta(s, Q) = \zeta(s, K)$. Also in I read that in general $|R(d, n)| = \sum_{m|n}{\chi_{d}(m)} = |I(d, n)|$ where $\chi_{d}$ is the Kronecker symbol mod $|d|$. All these facts tend to point out that there is a one-one correspondence between $R(d,n)$ and $I(d, n)$.
My question is that whether such a correspondence exists? If so could you explain this correspondence? Does this hold for $d > 0$ also?