I have a Rails application and I'm creating a notification system, the problem is that I do not know how to query for notifications not seen by a user in a practical way.
The schema of the notification table is as follows:
create_table "notifications", force: :cascade do |t|t.integer "performer_id"
t.string "content"
t.integer "kind"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["performer_id"], name: "index_notifications_on_performer_id"
end
The views table is:
create_table "visualizations", force: :cascade do |t|
t.integer "notification_id", null: false
t.integer "collaborator_id", null: false
t.boolean "visualized", default: false
t.index ["collaborator_id"], name: "index_visualizations_on_collaborator_id"
t.index ["notification_id"], name: "index_visualizations_on_notification_id"
end
Of course, I have the Notification
and Visualization
templates in the application.
What query could I do to select all notifications for a user whose view record does not exist in the view table?
I ask this because I do not have much experience in SQL to think about a query and I am also the only developer of the application.