Unique symmetrical pairs validation
<p>I created a scaffold in ror in order to contain some relations between elements</p>

<pre><code>+----------------------+
| left | right | score |
+----------------------+
</code></pre>

<p>So, if I have an entry <code>a, b, 10</code>, it means the relation from <code>a</code> to <code>b</code> is 10. But as left and right, represents <code>fk's</code> of the same kind of entity, we can conclude that the relation from <code>b</code> to <code>a</code> is also 10.</p>

<p>Doing something like <code>validates_uniqueness_of :left, :scope =&gt; [:right]</code> will not prevent the pair from appearing reverted in the table like so : <code>b, a, 10</code></p>

<p>I suppose something like :</p>

<pre><code>validates_uniqueness_of :left, :scope =&gt; [:right]
validates_uniqueness_of :right, :scope =&gt; [:left]
</code></pre>

<p>could do the trick, but is there a cleaner or more appropriate way to validate the uniqueness of pairs symmetrically ?</p>

<p>Once this is answered, the job is almost done.</p>

<p>How do I prevent the same value of appearing on both columns ?</p>

<p>eg. Such an entry should not be allowed : <code>a, a, 15</code></p>

<p>Thanks for your consideration.</p>