Lou пре 3 година
родитељ
комит
b3d44cd4b0

+ 1
- 2
app/models/activity.rb Прегледај датотеку

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

+ 4
- 0
app/models/record.rb Прегледај датотеку

@@ -0,0 +1,4 @@
1
+class Record < ApplicationRecord
2
+  belongs_to :user
3
+  belongs_to :task
4
+end

+ 2
- 3
app/models/user.rb Прегледај датотеку

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

+ 13
- 0
db/migrate/20210511212634_create_records.rb Прегледај датотеку

@@ -0,0 +1,13 @@
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 Прегледај датотеку

@@ -10,7 +10,7 @@
10 10
 #
11 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 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string "name", null: false
@@ -32,6 +32,19 @@ ActiveRecord::Schema.define(version: 2021_05_10_133939) do
32 32
     t.index ["user_id"], name: "index_joined_user_activities_on_user_id"
33 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 48
   create_table "tasks", force: :cascade do |t|
36 49
     t.string "name", null: false
37 50
     t.text "description"


+ 13
- 0
test/fixtures/records.yml Прегледај датотеку

@@ -0,0 +1,13 @@
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 Прегледај датотеку

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

Loading…
Откажи
Сачувај