Class: City
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- City
- Includes:
- IdentityCache
- Defined in:
- app/models/city.rb
Overview
Schema Information
Table name: cities
id :integer not null, primary key
active_not_expired_restaurants_count :integer default(0)
description :text(65535)
display_order :integer
home_description :string(255)
icon :string(191)
is_mini_homepage :boolean default(FALSE)
name :string(191)
name_th :string(191)
new_city :boolean default(FALSE)
restaurants_count :integer default(0)
title :string(191)
created_at :datetime not null
updated_at :datetime not null
country_id :integer not null
Indexes
index_cities_on_country_id (country_id)
Foreign Keys
fk_rails_... (country_id => countries.id)
Constant Summary collapse
- FILTERED_CITIES_KEY =
'City:filtered_cities'.freeze
Instance Attribute Summary collapse
-
#skip_adjust_display_order ⇒ Object
Returns the value of attribute skip_adjust_display_order.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from ApplicationRecord
Instance Attribute Details
#skip_adjust_display_order ⇒ Object
Returns the value of attribute skip_adjust_display_order.
35 36 37 |
# File 'app/models/city.rb', line 35 def skip_adjust_display_order @skip_adjust_display_order end |
Class Method Details
.filtered_cities ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/models/city.rb', line 93 def self.filtered_cities today = Date.current_date Rails.cache.fetch(FILTERED_CITIES_KEY, expires_in: CACHEFLOW.generate_expiry) do City.joins(:restaurants). where(restaurants: { active: true }). where('date(restaurants.expiry_date) >= ?', today). group('cities.id'). having('COUNT(restaurants.id) >= 10') end end |
.find_bangkok ⇒ Object
74 75 76 77 78 |
# File 'app/models/city.rb', line 74 def self.find_bangkok Rails.cache.fetch('City:find_bangkok', expires_in: CACHEFLOW.generate_expiry) do find_or_create_by name: 'Bangkok', country_id: Country.find_thailand.id end end |
.find_malaysia ⇒ Object
86 87 88 89 90 91 |
# File 'app/models/city.rb', line 86 def self.find_malaysia country_id = Country.find_malaysia.id Rails.cache.fetch('City:find_malaysia', expires_in: CACHEFLOW.generate_expiry) do find_or_create_by name: 'Kuala Lumpur', country_id: country_id end end |
.find_singapore ⇒ Object
80 81 82 83 84 |
# File 'app/models/city.rb', line 80 def self.find_singapore Rails.cache.fetch('City:find_singapore', expires_in: CACHEFLOW.generate_expiry) do find_or_create_by name: 'Singapore', country_id: Country.find_singapore.id end end |
Instance Method Details
#clear_filtered_cities ⇒ Object
107 108 109 110 111 |
# File 'app/models/city.rb', line 107 def clear_filtered_cities Rails.cache.delete FILTERED_CITIES_KEY true end |