Class: RestaurantVoucherSetting

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

Overview

RestaurantVoucherSetting Model

RestaurantVoucherSetting is responsible for storing voucher-related configuration for each restaurant. By separating these settings from the main `restaurants` table, we reduce table bloat and improve modularity, making it easier to extend voucher functionality in the future.

Associations

  • belongs_to :restaurant - Each voucher setting is linked to a single restaurant. (one-to-one relationship)

Usage Example

# Fetch voucher settings for a restaurant
settings = RestaurantVoucherSetting.find_by(restaurant_id: restaurant.id)

# Check if subsidized vouchers are accepted
if settings&.accept_subsidize_voucher
  # logic for subsidized vouchers
end

# Create or update settings
RestaurantVoucherSetting.create!(
  restaurant: restaurant,
  accept_subsidize_voucher: true
)

Suggestions for Future Extensions

  • Add validations (e.g., presence/uniqueness for the new columns)

  • Add additional voucher-related configuration columns as needed.

  • Implement scopes for querying by voucher acceptance.

  • Consider callbacks for auditing changes to voucher settings.

Schema Information

Table name: restaurant_voucher_settings

id                       :bigint           not null, primary key
accept_subsidize_voucher :boolean          default(FALSE)
created_at               :datetime         not null
updated_at               :datetime         not null
restaurant_id            :integer

Indexes

index_restaurant_voucher_settings_on_restaurant_id  (restaurant_id)

Foreign Keys

fk_rails_...  (restaurant_id => restaurants.id)

Method Summary

Methods inherited from ApplicationRecord

sync_carrierwave_url