Browse Source

Init Record model

Lou 3 years ago
parent
commit
b3d44cd4b0

+ 1
- 2
app/models/activity.rb View File

1
 class Activity < ApplicationRecord
1
 class Activity < ApplicationRecord
2
   belongs_to :author, class_name: "User"
2
   belongs_to :author, class_name: "User"
3
-  
4
   has_one :joined_user_activity
3
   has_one :joined_user_activity
5
   has_one :user, :through => :joined_user_activity
4
   has_one :user, :through => :joined_user_activity
6
-
7
   has_many :tasks
5
   has_many :tasks
6
+  has_many :records
8
 
7
 
9
   validates :name, presence: true
8
   validates :name, presence: true
10
   validates :author, presence: true
9
   validates :author, presence: true

+ 4
- 0
app/models/record.rb View File

1
+class Record < ApplicationRecord
2
+  belongs_to :user
3
+  belongs_to :task
4
+end

+ 2
- 3
app/models/user.rb View File

5
   validates :password_digest, presence: true
5
   validates :password_digest, presence: true
6
 
6
 
7
   has_many :created_activities, foreign_key: 'author_id', class_name: 'Activity', dependent: :destroy
7
   has_many :created_activities, foreign_key: 'author_id', class_name: 'Activity', dependent: :destroy
8
-
9
   has_many :joined_user_activities
8
   has_many :joined_user_activities
10
   has_many :activities, :through => :joined_user_activities
9
   has_many :activities, :through => :joined_user_activities
11
-
12
   has_many :tasks
10
   has_many :tasks
13
-
11
+  has_many :records
12
+  
14
   has_secure_password
13
   has_secure_password
15
 end
14
 end

+ 13
- 0
db/migrate/20210511212634_create_records.rb View File

1
+class CreateRecords < ActiveRecord::Migration[6.1]
2
+  def change
3
+    create_table :records do |t|
4
+      t.integer :duration, null: false
5
+      t.boolean :is_handled, default: false
6
+      t.references :handled_by, default: :null
7
+      t.references :user, null: false
8
+      t.references :task, null: false
9
+
10
+      t.timestamps
11
+    end
12
+  end
13
+end

+ 14
- 1
db/schema.rb View File

10
 #
10
 #
11
 # It's strongly recommended that you check this file into your version control system.
11
 # It's strongly recommended that you check this file into your version control system.
12
 
12
 
13
-ActiveRecord::Schema.define(version: 2021_05_10_133939) do
13
+ActiveRecord::Schema.define(version: 2021_05_11_212634) do
14
 
14
 
15
   create_table "activities", force: :cascade do |t|
15
   create_table "activities", force: :cascade do |t|
16
     t.string "name", null: false
16
     t.string "name", null: false
32
     t.index ["user_id"], name: "index_joined_user_activities_on_user_id"
32
     t.index ["user_id"], name: "index_joined_user_activities_on_user_id"
33
   end
33
   end
34
 
34
 
35
+  create_table "records", force: :cascade do |t|
36
+    t.integer "duration", null: false
37
+    t.boolean "is_handled", default: false
38
+    t.integer "handled_by_id"
39
+    t.integer "user_id", null: false
40
+    t.integer "task_id", null: false
41
+    t.datetime "created_at", precision: 6, null: false
42
+    t.datetime "updated_at", precision: 6, null: false
43
+    t.index ["handled_by_id"], name: "index_records_on_handled_by_id"
44
+    t.index ["task_id"], name: "index_records_on_task_id"
45
+    t.index ["user_id"], name: "index_records_on_user_id"
46
+  end
47
+
35
   create_table "tasks", force: :cascade do |t|
48
   create_table "tasks", force: :cascade do |t|
36
     t.string "name", null: false
49
     t.string "name", null: false
37
     t.text "description"
50
     t.text "description"

BIN
erd.pdf View File


+ 13
- 0
test/fixtures/records.yml View File

1
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+one:
4
+  duration: 2021-05-11 23:26:34
5
+  handled: false
6
+  user: one
7
+  task: one
8
+
9
+two:
10
+  duration: 2021-05-11 23:26:34
11
+  handled: false
12
+  user: two
13
+  task: two

+ 7
- 0
test/models/record_test.rb View File

1
+require "test_helper"
2
+
3
+class RecordTest < ActiveSupport::TestCase
4
+  # test "the truth" do
5
+  #   assert true
6
+  # end
7
+end

Loading…
Cancel
Save