Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lass UserInstructionRef < ActiveRecord::Base
- self.table_name = 'model_user_instruction_reference'
- self.inheritance_column = '' # чтобы поле type не воспринималось как название класса
- belongs_to :user
- belongs_to :session
- belongs_to :instruction
- belongs_to :sessions_upcoming, -> { upcoming }, class_name: 'Session', foreign_key: :session_id
- belongs_to :parent, class_name: 'UserInstructionRef'
- has_many :details, class_name: 'UserInstructionRefDetail'
- accepts_nested_attributes_for :sessions_upcoming, allow_destroy: true, reject_if: :all_blank
- accepts_nested_attributes_for :details, allow_destroy: true, reject_if: :all_blank
- default_scope { order :id => :desc }
- end
- class User < ActiveRecord::Base
- self.table_name = 'model_people'
- extend Enumerize
- attr_readonly :superadmin, :global_access
- validates_presence_of :surname, :first_name, :middle_name, :company
- validates_uniqueness_of :login, :scope => :customer_company_id
- validates_numericality_of :birth_year, :allow_nil => true
- validates_inclusion_of :labor_height_group, in: 1..3, allow_nil: true
- serialize :roles, Array
- enumerize :roles, in: [ :admin, :content_manager, :methodologist, :edu_center, :teacher, :finance, :apk ], multiple: true
- enumerize :category, in: [ :manager, :comission_member, :ordinary_staff, :teacher, :expert, :worker ]
- enumerize :sex, in: [ :male, :female ]
- enumerize :labor_height_category, in: [ :cat1, :cat2, :cat3, :cat4, :cat5, :general ]
- has_many :sessions_upcoming, -> { upcoming }, class_name: 'Session', foreign_key: :session_id
- has_many :sessions_finished, -> { finished }, class_name: 'Session'
- has_many :sessions_passed, -> { passed }, class_name: 'Session'
- has_many :sessions, -> { joins(:student=>:person) }, through: :students
- has_many :potoks, :foreign_key => 'author_id'
- has_and_belongs_to_many :protocols, :join_table => 'protocols_users'
- has_many :certificates
- has_many :user_course_topic_references
- has_many :exam_settings
- has_many :filter_presets
- has_and_belongs_to_many :teacher_courses, class_name: 'Course', join_table: 'teacher_modules', association_foreign_key: :program_id
- has_many :user_instruction_refs
- has_many :instructions, through: :user_instruction_refs
- has_many :actual_instruction_sessions, -> { where user_instruction_last: true }, class_name: 'Session', through: :user_instruction_refs, source: :session
- # has_many :actual_instruction_sessions, class_name: 'Session', through: :user_instruction_refs, source: :session
- has_many :penalties
- has_many :user_transfers
- has_one :active_session
- has_one :headed_active_session, class_name: 'ActiveSession', foreign_key: 'head_user_id'
- accepts_nested_attributes_for :direct_sessions, reject_if: :all_blank, allow_destroy: true
- accepts_nested_attributes_for :sessions_upcoming, reject_if: :all_blank, allow_destroy: false
- accepts_nested_attributes_for :user_course_topic_references, allow_destroy: true, reject_if: proc { |attributes| attributes['set'] != '1' }
- accepts_nested_attributes_for :exam_settings, reject_if: :all_blank, allow_destroy: true
- accepts_nested_attributes_for :company, reject_if: :all_blank
- #accepts_nested_attributes_for :teacher_course_reference, reject_if: :all_blank, allow_destroy: true
- accepts_nested_attributes_for :user_instruction_refs, reject_if: :all_blank, allow_destroy: true
- accepts_nested_attributes_for :penalties, allow_destroy: true, reject_if: :all_blank
- accepts_nested_attributes_for :user_transfers, allow_destroy: true, reject_if: :all_blank
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement