add user to moods
This commit is contained in:
parent
39f1035125
commit
71aaa32d15
4 changed files with 13 additions and 2 deletions
|
|
@ -1,4 +1,6 @@
|
|||
class Mood < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
class << self
|
||||
def history_for_a_year
|
||||
history(Date.today - 1.year, Date.today)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class User < ApplicationRecord
|
||||
has_secure_password
|
||||
has_many :sessions, dependent: :destroy
|
||||
has_many :moods
|
||||
|
||||
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
||||
|
||||
|
|
|
|||
5
db/migrate/20260127150339_add_user_to_moods.rb
Normal file
5
db/migrate/20260127150339_add_user_to_moods.rb
Normal 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
7
db/schema.rb
generated
|
|
@ -10,12 +10,14 @@
|
|||
#
|
||||
# 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|
|
||||
t.string "mode"
|
||||
t.datetime "recorded_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "user_id"
|
||||
t.index ["user_id"], name: "index_moods_on_user_id"
|
||||
end
|
||||
|
||||
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.string "chip_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"
|
||||
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
|
||||
end
|
||||
|
||||
add_foreign_key "moods", "users"
|
||||
add_foreign_key "rfid_tags", "users"
|
||||
add_foreign_key "sessions", "users"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue