Advertisement
alewtina

Untitled

Jan 10th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 3.54 KB | None | 0 0
  1. lass UserInstructionRef < ActiveRecord::Base
  2.     self.table_name = 'model_user_instruction_reference'
  3.     self.inheritance_column = '' # чтобы поле type не воспринималось как название класса
  4.  
  5.     belongs_to :user
  6.     belongs_to :session
  7.     belongs_to :instruction
  8.     belongs_to :sessions_upcoming, -> { upcoming }, class_name: 'Session', foreign_key: :session_id
  9.     belongs_to :parent, class_name: 'UserInstructionRef'
  10.  
  11.     has_many :details, class_name: 'UserInstructionRefDetail'
  12.  
  13.     accepts_nested_attributes_for :sessions_upcoming, allow_destroy: true, reject_if: :all_blank
  14.     accepts_nested_attributes_for :details, allow_destroy: true, reject_if: :all_blank
  15.  
  16.     default_scope { order :id => :desc }
  17.  
  18. end
  19.  
  20.  
  21.  
  22. class User < ActiveRecord::Base
  23.     self.table_name = 'model_people'
  24.     extend Enumerize
  25.  
  26.     attr_readonly :superadmin, :global_access
  27.  
  28.     validates_presence_of :surname, :first_name, :middle_name, :company
  29.     validates_uniqueness_of :login, :scope => :customer_company_id
  30.     validates_numericality_of :birth_year, :allow_nil => true
  31.     validates_inclusion_of :labor_height_group, in: 1..3, allow_nil: true
  32.  
  33.     serialize :roles, Array
  34.  
  35.     enumerize :roles, in: [ :admin, :content_manager, :methodologist, :edu_center, :teacher, :finance, :apk ], multiple: true
  36.     enumerize :category, in: [ :manager, :comission_member, :ordinary_staff, :teacher, :expert, :worker ]
  37.     enumerize :sex, in: [ :male, :female ]
  38.     enumerize :labor_height_category, in: [ :cat1, :cat2, :cat3, :cat4, :cat5, :general ]
  39.  
  40.     has_many :sessions_upcoming, -> { upcoming }, class_name: 'Session', foreign_key: :session_id
  41.     has_many :sessions_finished, -> { finished }, class_name: 'Session'
  42.     has_many :sessions_passed, -> { passed }, class_name: 'Session'
  43.     has_many :sessions, -> { joins(:student=>:person) }, through: :students
  44.     has_many :potoks, :foreign_key => 'author_id'
  45.     has_and_belongs_to_many :protocols, :join_table => 'protocols_users'
  46.     has_many :certificates
  47.     has_many :user_course_topic_references
  48.     has_many :exam_settings
  49.     has_many :filter_presets
  50.     has_and_belongs_to_many :teacher_courses, class_name: 'Course', join_table: 'teacher_modules', association_foreign_key: :program_id
  51.     has_many :user_instruction_refs
  52.     has_many :instructions, through: :user_instruction_refs
  53.     has_many :actual_instruction_sessions, -> { where user_instruction_last: true }, class_name: 'Session', through: :user_instruction_refs, source: :session
  54.     # has_many :actual_instruction_sessions, class_name: 'Session', through: :user_instruction_refs, source: :session
  55.     has_many :penalties
  56.     has_many :user_transfers
  57.  
  58.     has_one :active_session
  59.     has_one :headed_active_session, class_name: 'ActiveSession', foreign_key: 'head_user_id'
  60.  
  61.     accepts_nested_attributes_for :direct_sessions, reject_if: :all_blank, allow_destroy: true
  62.     accepts_nested_attributes_for :sessions_upcoming, reject_if: :all_blank, allow_destroy: false
  63.     accepts_nested_attributes_for :user_course_topic_references, allow_destroy: true, reject_if: proc { |attributes| attributes['set'] != '1' }
  64.     accepts_nested_attributes_for :exam_settings, reject_if: :all_blank, allow_destroy: true
  65.     accepts_nested_attributes_for :company, reject_if: :all_blank
  66.     #accepts_nested_attributes_for :teacher_course_reference, reject_if: :all_blank, allow_destroy: true
  67.     accepts_nested_attributes_for :user_instruction_refs, reject_if: :all_blank, allow_destroy: true
  68.     accepts_nested_attributes_for :penalties, allow_destroy: true, reject_if: :all_blank
  69.     accepts_nested_attributes_for :user_transfers, allow_destroy: true, reject_if: :all_blank
  70.  
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement