activerecord - Bidirectional graph in rails -
I have a simple model "match" that should save two-directional links between two objects).
The problem I have is that for every bi-directional matching, I find that I get two database entries i like 1: obj1 -> obj2, 2: obj2 -> obj1
How can I use validates_uniqueness_of
to avoid here? I tried
validates_uniqueness_of: obj1_id ,: scope = & gt; : Obj2_id validates_uniqueness_of: obj2_id,: scope = & gt; : Obj1_id
but that was not working
< Code> Validations_Infinity_of: obj1_id ,: scope = & gt; : Obj2_id DEF valid if search ("before, conditions:";: obj1 = & gt; obj2,: obj2 = & gt; obj1}) errors.add_to_base ("already exists") end of end
Add some unique database index to pretty ugly.
Comments
Post a Comment