Class: RelationshipBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/models/relationship_builder.rb

Class Method Summary collapse

Class Method Details

.build(person, other, relation) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'app/models/relationship_builder.rb', line 2

def self.build(person, other, relation)
  ActiveRecord::Base.transaction do
    relationship = person.relationships.create(:other => other, :relation => relation)
    relationship.save!
    inverse = other.relationships.create(:other => person, :relation => relation.inverse, :inverse => relationship)
    inverse.save!
    relationship.update_attribute(:inverse_id, inverse.id)
    relationship
  end
end