Sha256: b6df48f0e843848e04b0ba0459a197fe4d14aff19d2ebbec24e6b11955c01cab

Contents?: true

Size: 597 Bytes

Versions: 4

Compression:

Stored size: 597 Bytes

Contents

# encoding: UTF-8
module AlchemyCrm
  class ContactGroup < ActiveRecord::Base

    acts_as_taggable_on :contact_tags

    has_many :filters, :dependent => :destroy, :class_name => "AlchemyCrm::ContactGroupFilter"

    validates_presence_of :name

    accepts_nested_attributes_for :filters, :allow_destroy => true

    def contacts
      Contact.tagged_with(self.contact_tags, :any => true).where(filters_sql_string)
    end

    def filters_sql_string
      filters.map(&:sql_string).join(' AND ')
    end

    def humanized_name
      "#{self.name} (#{self.contacts.length})"
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alchemy_crm-2.0.5 app/models/alchemy_crm/contact_group.rb
alchemy_crm-2.0.4.1 app/models/alchemy_crm/contact_group.rb
alchemy_crm-2.0.3 app/models/alchemy_crm/contact_group.rb
alchemy_crm-2.0.2 app/models/alchemy_crm/contact_group.rb