add user to moods

This commit is contained in:
Christophe Robillard 2026-01-28 16:34:06 +01:00
parent 39f1035125
commit 71aaa32d15
4 changed files with 13 additions and 2 deletions

View file

@ -1,4 +1,6 @@
class Mood < ApplicationRecord class Mood < ApplicationRecord
belongs_to :user
class << self class << self
def history_for_a_year def history_for_a_year
history(Date.today - 1.year, Date.today) history(Date.today - 1.year, Date.today)

View file

@ -1,6 +1,7 @@
class User < ApplicationRecord class User < ApplicationRecord
has_secure_password has_secure_password
has_many :sessions, dependent: :destroy has_many :sessions, dependent: :destroy
has_many :moods
normalizes :email_address, with: ->(e) { e.strip.downcase } normalizes :email_address, with: ->(e) { e.strip.downcase }

View file

@ -0,0 +1,5 @@
class AddUserToMoods < ActiveRecord::Migration[8.0]
def change
add_reference :moods, :user, foreign_key: true
end
end

7
db/schema.rb generated
View file

@ -10,12 +10,14 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2026_01_27_134053) do ActiveRecord::Schema[8.0].define(version: 2026_01_27_150339) do
create_table "moods", force: :cascade do |t| create_table "moods", force: :cascade do |t|
t.string "mode" t.string "mode"
t.datetime "recorded_at" t.datetime "recorded_at"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["user_id"], name: "index_moods_on_user_id"
end end
create_table "rfid_tags", force: :cascade do |t| create_table "rfid_tags", force: :cascade do |t|
@ -25,7 +27,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_27_134053) do
t.datetime "updated_at", default: -> { "CURRENT_DATE" }, null: false t.datetime "updated_at", default: -> { "CURRENT_DATE" }, null: false
t.string "chip_id" t.string "chip_id"
t.integer "user_id" t.integer "user_id"
t.index ["identifier"], name: "index_rfid_tags_on_identifier", unique: true t.index ["identifier"], name: "index_rfid_tags_on_identifier"
t.index ["user_id"], name: "index_rfid_tags_on_user_id" t.index ["user_id"], name: "index_rfid_tags_on_user_id"
end end
@ -47,6 +49,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_27_134053) do
t.index ["email_address"], name: "index_users_on_email_address", unique: true t.index ["email_address"], name: "index_users_on_email_address", unique: true
end end
add_foreign_key "moods", "users"
add_foreign_key "rfid_tags", "users" add_foreign_key "rfid_tags", "users"
add_foreign_key "sessions", "users" add_foreign_key "sessions", "users"
end end