๐Ÿ“ฆ obafemitayor / newsletter-subscription-application

๐Ÿ“„ category.rb ยท 25 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25class Category < ApplicationRecord
  # Soft delete
  scope :active, -> { where(deleted_at: nil) }

  # Relationships
  has_many :subscriptions, dependent: :destroy
  has_many :customers, through: :subscriptions

  # Validations
  validates :name, presence: true, uniqueness: { case_sensitive: false }

  # Instance methods
  def soft_delete
    update(deleted_at: Time.current)
  end

  def restore
    update(deleted_at: nil)
  end

  def deleted?
    deleted_at.present?
  end
end