Still the multiple reference to single column

It works now, thought I still need to figure what’s happened under the hood.

   1: class Friendship < ActiveRecord::Base
   2:   belongs_to :user  
   3:   belongs_to :friend, :class_name => 'User', :foreign_key => 'friend_id'
   4: end
   1: class User < ActiveRecord::Base
   2:   has_many :friendships  
   3:   has_many :friends, :through => :friendships
   4: end

 

And finally, I got the model of my script relationship 🙂

   1: class Script < ActiveRecord::Base
   2:     has_many :relationships
   3:     has_many :related_scripts, :through=>:relationships
   4:   
   5:     validates_presence_of :name
   6:     validates_uniqueness_of :name
   7:  
   8:   def validate
   9:     errors.add_to_base "Invalid pattern." if name !=~ /^component.*/ 
  10:   end  
  11:   
  12:   def validate
  13:     errors.add_to_base "Parameter should not exist." if name =~ /.*=.*/
  14:   end
  15: end

 

   1: class Relationship < ActiveRecord::Base
   2:   belongs_to :script
   3:   belongs_to :related_script, :class_name=>'Script', :foreign_key=>'related_script_id'
   4: end