ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

23 lines
892 B

  1. class User < ApplicationRecord
  2. enum :role, { guest: 'guest', member: 'member', admin: 'admin' }
  3. validates :name, length: { maximum: 255 }
  4. validates :inheritance_code, presence: true, length: { maximum: 64 }
  5. validates :role, presence: true, inclusion: { in: roles.keys }
  6. validates :banned, inclusion: { in: [true, false] }
  7. has_many :posts
  8. has_many :settings
  9. has_many :ip_addresses
  10. has_many :user_ips, dependent: :destroy
  11. has_many :ip_addresses, through: :user_ips
  12. has_many :user_post_views, dependent: :destroy
  13. has_many :viewed_posts, through: :user_post_views, source: :post
  14. has_many :created_wiki_pages, class_name: 'WikiPage', foreign_key: 'created_user_id', dependent: :nullify
  15. has_many :updated_wiki_pages, class_name: 'WikiPage', foreign_key: 'updated_user_id', dependent: :nullify
  16. def viewed? post
  17. user_post_views.exists? post_id: post.id
  18. end
  19. end