-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcollection.rb
27 lines (23 loc) · 1.03 KB
/
collection.rb
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
# frozen_string_literal: true
class Collection < ApplicationRecord
include RoleControl::Owned
include Activatable
include PgSearch::Model
include SluggedName
has_and_belongs_to_many :projects
has_many :collections_subjects,
-> { order(id: :desc) },
dependent: :destroy
has_many :subjects, through: :collections_subjects
has_many :collection_roles, -> { where.not("access_control_lists.roles = '{}'") }, class_name: 'AccessControlList', as: :resource
has_many :user_collection_preferences, dependent: :destroy
belongs_to :default_subject, class_name: 'Subject'
validates :display_name, presence: true
validates :private, inclusion: { in: [true, false], message: "can't be blank" }
## TODO: UniqueForOwnerValidator potential has locking issues
validates_with Validators::UniqueForOwnerValidator, Validators::OneFavoritePerOwnerValidator
pg_search_scope :search_display_name,
against: :display_name,
using: :trigram,
ranked_by: ':trigram'
end