app/models/entities/campaign.rb in fat_free_crm-0.18.2 vs app/models/entities/campaign.rb in fat_free_crm-0.19.0
- old
+ new
@@ -30,20 +30,20 @@
# updated_at :datetime
# background_info :string(255)
#
class Campaign < ActiveRecord::Base
- belongs_to :user
- belongs_to :assignee, class_name: "User", foreign_key: :assigned_to
+ belongs_to :user, optional: true # TODO: Is this really optional?
+ belongs_to :assignee, class_name: "User", foreign_key: :assigned_to, optional: true # TODO: Is this really optional?
has_many :tasks, as: :asset, dependent: :destroy # , :order => 'created_at DESC'
has_many :leads, -> { order "id DESC" }, dependent: :destroy
has_many :opportunities, -> { order "id DESC" }, dependent: :destroy
has_many :emails, as: :mediator
serialize :subscribed_users, Set
- scope :state, ->(filters) {
+ scope :state, lambda { |filters|
where('status IN (?)' + (filters.delete('other') ? ' OR status IS NULL' : ''), filters)
}
scope :created_by, ->(user) { where(user_id: user.id) }
scope :assigned_to, ->(user) { where(assigned_to: user.id) }
@@ -101,12 +101,10 @@
private
# Make sure end date > start date.
#----------------------------------------------------------------------------
def start_and_end_dates
- if (starts_on && ends_on) && (starts_on > ends_on)
- errors.add(:ends_on, :dates_not_in_sequence)
- end
+ errors.add(:ends_on, :dates_not_in_sequence) if (starts_on && ends_on) && (starts_on > ends_on)
end
# Make sure at least one user has been selected if the campaign is being shared.
#----------------------------------------------------------------------------
def users_for_shared_access