activerecord - Bidirectional graph in rails -


I have a simple model "match" that should save two-directional links between two objects).

Class matches & lt; ActiveRecord :: Base is_to: obj1 ,: class_name = & gt; "MyMold" ,: Foreign_Key => : Obj1_id belongs_to: obj2 ,: class_name = & gt; "MyMold" ,: Foreign_Key => : Obj2_id ... end

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

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -