Class: Household

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/household.rb

Instance Method Summary collapse

Instance Method Details

#actionsObject



37
38
39
# File 'app/models/household.rb', line 37

def actions
  Action.where(:person_id => individuals.pluck(:id))
end

#addressesObject



41
42
43
# File 'app/models/household.rb', line 41

def addresses
  Address.where(:person_id => individuals.pluck(:id))
end

#lifetime_donationsObject



21
22
23
# File 'app/models/household.rb', line 21

def lifetime_donations
  individuals.sum(:lifetime_donations)
end

#lifetime_donations_countObject



29
30
31
# File 'app/models/household.rb', line 29

def lifetime_donations_count
  individuals.includes(:orders).map { |i| i.orders.map { |o| o.donations.count }.sum }.sum
end

#lifetime_ticket_countObject



25
26
27
# File 'app/models/household.rb', line 25

def lifetime_ticket_count
  Ticket.where(:buyer_id => individuals.pluck(:id)).count
end

#lifetime_ticket_valueObject



17
18
19
# File 'app/models/household.rb', line 17

def lifetime_ticket_value
  individuals.sum(:lifetime_ticket_value)
end

#lifetime_valueObject



13
14
15
# File 'app/models/household.rb', line 13

def lifetime_value
  individuals.sum(:lifetime_value)
end

#notesObject



33
34
35
# File 'app/models/household.rb', line 33

def notes
  Note.where(:person_id => individuals.pluck(:id))
end

#tagsObject



45
46
47
# File 'app/models/household.rb', line 45

def tags
  ActsAsTaggableOn::Tagging.where(:taggable_type => "Person", :taggable_id => individuals.pluck(:id))
end

#update_member_addressesObject



49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/household.rb', line 49

def update_member_addresses
  return unless address.present?

  individuals.each do |individual|
    if individual.address.present?
      individual.address.update_attributes(address.values_hash)
    else
      individual.address = address.dup
    end
  end
end