File: user.rb

package info (click to toggle)
rails 2%3A7.2.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,348 kB
  • sloc: ruby: 349,797; javascript: 30,703; yacc: 46; sql: 43; sh: 29; makefile: 27
file content (38 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require "models/job"

class User < ActiveRecord::Base
  has_secure_password validations: false
  has_secure_password :recovery_password, validations: false

  has_secure_token
  has_secure_token :auth_token, length: 36

  has_and_belongs_to_many :jobs_pool,
    class_name: "Job",
    join_table: "jobs_pool"

  has_one :room
  has_one :owned_room, class_name: "Room", foreign_key: "owner_id"
  has_one :family_tree, -> { where(token: nil) }, foreign_key: "member_id"
  has_one :family, through: :family_tree
  has_many :family_members, through: :family, source: :members

  has_one :let_room, class_name: "Room", foreign_key: "landlord_id", dependent: :destroy
  has_one :rented_room, class_name: "Room", foreign_key: "tenant_id", dependent: :destroy
end

class UserWithNotification < User
  after_create -> { Notification.create! message: "A new user has been created." }
end

module Nested
  class User < ActiveRecord::Base
    self.table_name = "users"
  end

  class NestedUser < ActiveRecord::Base
    has_many :nested_users
  end
end