Class: Risk

Inherits:
ApplicationRecord show all
Defined in:
app/models/risk.rb

Overview

This model manage the risks of work

Relations

has many CategoryRisk has many Category, through CategoryRisk

Validates

Default scope

  • order by title asc

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

#div

Instance Attribute Details

#codeString

Returns Short code of Risk.

Returns:

  • (String)

    Short code of Risk



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end

#created_atDateTime

Returns when the record was created.

Returns:

  • (DateTime)

    when the record was created



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end

#idInteger

Returns unique identifier for Risk.

Returns:

  • (Integer)

    unique identifier for Risk



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end

#printedBoolean

Returns if Risk enter in the reports, can’t be null, default is true.

Returns:

  • (Boolean)

    if Risk enter in the reports, can’t be null, default is true



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end

#titleString

Returns full title of Risk, can’t be null, default is empty string.

Returns:

  • (String)

    full title of Risk, can’t be null, default is empty string



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end

#updated_atDateTime

Returns when the record was updated.

Returns:

  • (DateTime)

    when the record was updated



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end

Class Method Details

.printedArray

Returns all Risk with printed true, order by code.

Returns:

  • (Array)

    all Risk with printed true, order by code



28
29
30
31
32
33
34
35
36
37
# File 'app/models/risk.rb', line 28

class Risk < ApplicationRecord
  has_many :category_risks, dependent: :restrict_with_exception
  has_many :categories, through: :category_risks

  validates :title, presence: true, uniqueness: true

  default_scope { order('title asc') }

  scope :printed, -> { unscoped.where(printed: true).order(:code) }
end