I created a scaffold in ror in order to contain some relations between elements
+----------------------+
| left | right | score |
+----------------------+
So, if I have an entry a, b, 10
, it means the relation from a
to b
is 10. But as left and right, represents fk's
of the same kind of entity, we can conclude that the relation from b
to a
is also 10.
Doing something like validates_uniqueness_of :left, :scope => [:right]
will not prevent the pair from appearing reverted in the table like so : b, a, 10
I suppose something like :
validates_uniqueness_of :left, :scope => [:right]
validates_uniqueness_of :right, :scope => [:left]
could do the trick, but is there a cleaner or more appropriate way to validate the uniqueness of pairs symmetrically ?
Once this is answered, the job is almost done.
How do I prevent the same value of appearing on both columns ?
eg. Such an entry should not be allowed : a, a, 15
Thanks for your consideration.