Class: RelationBuilder

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

Class Method Summary collapse

Class Method Details

.build(description, inverse_description, pi, pc, oi, oc) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/relation_builder.rb', line 14

def self.build(description, inverse_description, pi, pc, oi, oc)
  ActiveRecord::Base.transaction do
    relation = Relation.create(:description => description,
                               :person_can_be_individual => pi,
                               :person_can_be_company => pc,
                               :other_can_be_individual => oi,
                               :other_can_be_company => oc)

    inverse = relation.create_inverse(:description => inverse_description,
                                      :person_can_be_individual => oi,
                                      :person_can_be_company => oc,
                                      :other_can_be_individual => pi,
                                      :other_can_be_company => pc,
                                      :inverse => relation)
    relation.update_attribute(:inverse_id, inverse.id)
    relation
  end
end

.build_single(description, pi, pc, oi, oc) ⇒ Object



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

def self.build_single(description, pi, pc, oi, oc)
  ActiveRecord::Base.transaction do
    relation = Relation.create(:description => description,
                               :person_can_be_individual => pi,
                               :person_can_be_company => pc,
                               :other_can_be_individual => oi,
                               :other_can_be_company => oc)
    relation.update_attribute(:inverse_id, relation.id)
    relation
  end
end