negos_app/app/models/reseaux.rb
2019-05-23 20:59:03 +02:00

43 lines
1.1 KiB
Ruby

class Reseaux < ActiveRecord::Base
belongs_to :chef_reseau, :class_name => "Customer"
belongs_to :logo_image_file, :class_name => "ImageFile"
belongs_to :background_image_file, :class_name => "ImageFile"
has_many :reseaux_customers, :dependent => :destroy
has_many :customers, :through => :reseaux_customers
has_many :domains, :through => :customers
has_many :needs, :through => :customers
has_many :offer_reseauxes, :dependent => :destroy
has_many :offers, :through => :offer_reseauxes
belongs_to :menu_item
has_many :thing_conversations, :as => :thing, :dependent => :destroy
has_many :conversations, :through => :thing_conversations
has_many :product_orders
acts_as_tree
before_create do
self.generate_token
end
def generate_token
self.token = loop do
token = SecureRandom.hex(3)
token = token.upcase
break token unless Reseaux.exists?(token: token) or token.include?("0") or token.include?("O") or token.include?("1") or token.include?("L") or token.include?("I")
end
end
end