Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # frozen_string_literal: true
- class Market < ApplicationRecord
- audited
- after_create :create_market_currencies, :create_market_units
- strip_attributes collapse_spaces: true
- validates :title, :timezone, presence: true
- belongs_to :currency
- has_many :user_markets
- has_many :stocks
- has_many :categories
- has_many :market_units
- has_many :market_currencies
- has_many :currencies, -> { where 'market_currencies.is_active = true' },
- through: :market_currencies
- has_many :suppliers
- has_many :option_types
- has_many :option_values, -> { where 'option_types.is_active = true' },
- through: :option_types
- default_scope { order(title: :asc) }
- def create_market_currencies
- Currency.all.each do |c|
- mc = MarketCurrency.new
- mc.market_id = id
- mc.currency_id = c.id
- mc.save
- end
- end
- def create_market_units
- I18n.t('market_units').each do |u|
- mc = MarketUnit.new
- mc.market_id = id
- mc.title = u[1]
- mc.save
- end
- end
- def top_categories
- categories.where(parent_id: nil)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement