Class: SuggestionTag

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Defined in:
app/models/suggestion_tag.rb

Overview

Schema Information

Table name: suggestion_tags

id                 :bigint           not null, primary key
name_cn            :string(191)
name_en            :string(191)
name_th            :string(191)
promotion_type     :string(191)
rank               :integer
suggestion_type    :string(191)
url                :text(65535)
created_at         :datetime         not null
updated_at         :datetime         not null
interesting_tag_id :integer
outlet_tag_id      :integer
promotion_tag_id   :integer
restaurant_id      :bigint

Indexes

index_suggestion_tags_on_interesting_tag_id  (interesting_tag_id)
index_suggestion_tags_on_outlet_tag_id       (outlet_tag_id)
index_suggestion_tags_on_promotion_tag_id    (promotion_tag_id)
index_suggestion_tags_on_restaurant_id       (restaurant_id)

Foreign Keys

suggestion_tags_restaurant_tags_FK    (outlet_tag_id => restaurant_tags.id)
suggestion_tags_restaurant_tags_FK_1  (interesting_tag_id => restaurant_tags.id)
suggestion_tags_restaurant_tags_FK_2  (promotion_tag_id => restaurant_tags.id)

Constant Summary collapse

SUGGESTION_TYPE =
{
  promotion: 'Promotion',
  interesting: 'Interesting',
  outlet: 'Outlet',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Class Method Details

.suggest_typesObject



57
58
59
# File 'app/models/suggestion_tag.rb', line 57

def self.suggest_types
  SuggestionTag::SUGGESTION_TYPE.keys
end

Instance Method Details

#name(lang = MyLocaleManager.normalize_locale, for_api: false) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'app/models/suggestion_tag.rb', line 61

def name(lang = MyLocaleManager.normalize_locale, for_api: false)
  if !respond_to?("name_#{lang}".to_sym)
    lang = MyLocaleManager.default_locale
  end

  return send("name_#{lang}") unless for_api

  send("name_#{lang}").presence || send("name_#{MyLocaleManager.default_locale}")
end