Notifications are all related to a Bubble
This commit is contained in:
@@ -4,6 +4,8 @@ class Bubble < ApplicationRecord
|
||||
belongs_to :bucket, touch: true
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
|
||||
has_many :notifications, dependent: :destroy
|
||||
|
||||
has_one_attached :image, dependent: :purge_later
|
||||
|
||||
before_save :set_default_title
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Notification < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to :bubble
|
||||
belongs_to :resource, polymorphic: true
|
||||
|
||||
scope :unread, -> { where(read: false) }
|
||||
|
||||
@@ -9,7 +9,7 @@ class Notifier
|
||||
|
||||
def generate
|
||||
recipients.map do |recipient|
|
||||
Notification.create! user: recipient, creator: event.creator, resource: resource, body: body
|
||||
Notification.create! user: recipient, creator: event.creator, bubble: bubble, resource: resource, body: body
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ class CreateNotifications < ActiveRecord::Migration[8.1]
|
||||
create_table :notifications do |t|
|
||||
t.references :user, null: false, foreign_key: true
|
||||
t.references :creator, null: false, foreign_key: { to_table: :users }
|
||||
t.references :bubble, null: false, foreign_key: true
|
||||
t.references :resource, null: false, polymorphic: true, index: true
|
||||
t.boolean :read, default: false, null: false
|
||||
t.text :body, null: false
|
||||
|
||||
Generated
+3
@@ -179,12 +179,14 @@ ActiveRecord::Schema[8.1].define(version: 2025_01_09_153649) do
|
||||
create_table "notifications", force: :cascade do |t|
|
||||
t.integer "user_id", null: false
|
||||
t.integer "creator_id", null: false
|
||||
t.integer "bubble_id", null: false
|
||||
t.string "resource_type", null: false
|
||||
t.integer "resource_id", null: false
|
||||
t.boolean "read", default: false, null: false
|
||||
t.text "body", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["bubble_id"], name: "index_notifications_on_bubble_id"
|
||||
t.index ["creator_id"], name: "index_notifications_on_creator_id"
|
||||
t.index ["resource_type", "resource_id"], name: "index_notifications_on_resource"
|
||||
t.index ["user_id", "read", "created_at"], name: "index_notifications_on_user_id_and_read_and_created_at", order: { read: :desc, created_at: :desc }
|
||||
@@ -259,6 +261,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_01_09_153649) do
|
||||
add_foreign_key "bubbles", "workflow_stages", column: "stage_id"
|
||||
add_foreign_key "events", "event_summaries", column: "summary_id"
|
||||
add_foreign_key "messages", "bubbles"
|
||||
add_foreign_key "notifications", "bubbles"
|
||||
add_foreign_key "notifications", "users"
|
||||
add_foreign_key "notifications", "users", column: "creator_id"
|
||||
add_foreign_key "pops", "bubbles"
|
||||
|
||||
Vendored
+2
@@ -1,6 +1,7 @@
|
||||
logo_created_kevin:
|
||||
user: kevin
|
||||
creator: david
|
||||
bubble: logo
|
||||
resource: logo (Bubble)
|
||||
read: false
|
||||
body: "created: The logo isn't big enough"
|
||||
@@ -9,6 +10,7 @@ logo_created_kevin:
|
||||
layout_created_kevin:
|
||||
user: kevin
|
||||
creator: david
|
||||
bubble: logo
|
||||
resource: layout (Bubble)
|
||||
read: false
|
||||
body: "created: Layout is broken"
|
||||
|
||||
Reference in New Issue
Block a user