Introduce scopes for finding bubbles assigned to or by someone

This commit is contained in:
Jeffrey Hardy
2024-10-02 15:47:33 -04:00
parent 889dfdd06a
commit da21a071b8
2 changed files with 3 additions and 1 deletions
+3
View File
@@ -6,6 +6,9 @@ module Bubble::Assignable
has_many :assignees, through: :assignments
has_many :assigners, through: :assignments
scope :assigned_to, ->(user) { joins(:assignments).where(assignments: { assignee: user }) }
scope :assigned_by, ->(user) { joins(:assignments).where(assignments: { assigner: user }) }
end
def assign(users, assigner: Current.user)
-1
View File
@@ -8,7 +8,6 @@ class User < ApplicationRecord
has_many :buckets, through: :accesses
has_many :bubbles, through: :buckets
has_many :assignments, foreign_key: :assignee_id, dependent: :destroy
has_many :assignings, foreign_key: :assigner_id, class_name: "Assignment"
has_many :assigned_bubbles, through: :assignments, source: :bubble