added scope functionality

This commit is contained in:
Giga Chubinidze 2023-07-19 10:31:14 +04:00
parent e1ab7bda4b
commit e381651df2
2 changed files with 6 additions and 1 deletions

View file

@ -71,6 +71,11 @@ class Project < ApplicationRecord
end
end)
scope :not_assigned_to_user, lambda { |user|
left_joins(:user_assignments)
.where('user_assignments.user_id = ? AND user_assignments.id IS NULL', user.id)
}
scope :templates, -> { where(template: true) }
after_create :auto_assign_project_members, if: :visible?

View file

@ -13,7 +13,7 @@ module Toolbars
@project_folders = current_user.current_team.project_folders.where(id: project_folder_ids)
@items = @projects + @project_folders
@not_assigned = @projects.any? { |project| !project.assigned_users.include?(current_user) }
@not_assigned = current_user.current_team.projects.not_assigned_to_user(current_user).any?
@single = @items.length == 1