Class: Spina::Admin::Conferences::Room

Inherits:
ApplicationRecord show all
Defined in:
app/models/spina/admin/conferences/room.rb

Overview

Room records.

Validators

Presence

#number, #building.

Translations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#buildingString?

Returns the building of the room.

Returns:

  • (String, nil)

    the building of the room



21
# File 'app/models/spina/admin/conferences/room.rb', line 21

translates :building, :number, fallbacks: true

#institutionInstitution?

Returns directly associated institution.

Returns:

  • (Institution, nil)

    directly associated institution

See Also:



29
# File 'app/models/spina/admin/conferences/room.rb', line 29

belongs_to :institution, -> { includes(:translations) }, inverse_of: :rooms, autosave: true, touch: true

#numberString?

Returns the number of the room.

Returns:

  • (String, nil)

    the number of the room



21
# File 'app/models/spina/admin/conferences/room.rb', line 21

translates :building, :number, fallbacks: true

#presentationsActiveRecord::Relation

Returns Presentations associated with #sessions.

Returns:

  • (ActiveRecord::Relation)

    Presentations associated with #sessions

See Also:



39
# File 'app/models/spina/admin/conferences/room.rb', line 39

has_many :presentations, -> { distinct.includes(:translations) }, through: :sessions

#sessionsActiveRecord::Relation

Note:

A room cannot be destroyed if it has dependent sessions.

Returns directly associated sessions.

Returns:

  • (ActiveRecord::Relation)

    directly associated sessions

See Also:



34
# File 'app/models/spina/admin/conferences/room.rb', line 34

has_many :sessions, -> { includes(:translations) }, inverse_of: :room, dependent: :restrict_with_error

Instance Method Details

#nameString

Returns the building and number of the room.

Returns:

  • (String)

    the building and number of the room



44
45
46
47
48
# File 'app/models/spina/admin/conferences/room.rb', line 44

def name
  return if building.blank? || number.blank?

  Room.human_attribute_name :name, building: building, number: number
end

#sortedActiveRecord::Relation

Returns all rooms, ordered by building and number.

Returns:

  • (ActiveRecord::Relation)

    all rooms, ordered by building and number



24
# File 'app/models/spina/admin/conferences/room.rb', line 24

scope :sorted, -> { i18n.order :building, :number }