@devkrd

Есть две модели room и hotel, как привязать множество room к одному hotel?

class Hotel < ApplicationRecord
  belongs_to :user
  has_many :pictures, :as => :imageable

  validates :hotel_type, presence:true
  validates :num_room, presence:true
  validates :food, presence:true

  geocoded_by :address
  after_validation :geocode, if: :address_changed?

  def cover_photo(size)
    if self.pictures.length > 0
      self.pictures[0].image.url(size)
    else
      "blank.jpg"
    end
  end
end

class Room < ApplicationRecord
  enum instant: {Запрос: 0, Мгновенное: 1}

  belongs_to :user
  has_many :pictures, :as => :imageable
  has_many :reservations

  has_many :guest_reviews
  has_many :calendars

  geocoded_by :address
  after_validation :geocode, if: :address_changed?

  validates :home_type, presence: true
  validates :room_type, presence: true
  validates :accommodate, presence: true
  validates :bed_room, presence: true
  validates :bath_room, presence: true


  def cover_photo(size)
    if self.pictures.length > 0
      self.pictures[0].image.url(size)
    else
      "blank.jpg"
    end
  end

  def average_rating
    guest_reviews.count == 0 ? 0 : guest_reviews.average(:star).round(2).to_i
  end
end
  • Вопрос задан
  • 124 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы