parent
f46cee65db
commit
1be63d19af
@ -1,4 +1,9 @@
|
||||
class ChallengeAnswer < ApplicationRecord
|
||||
default_scope { order("challenge_answers.level asc") }
|
||||
belongs_to :challenge
|
||||
has_many :game_answers, :dependent => :destroy
|
||||
|
||||
def view_answer_time(user_id)
|
||||
game_answers.where(user_id: user_id).last&.view_time
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
class GameAnswer < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :game
|
||||
belongs_to :challenge_answer
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
class CreateGameAnswers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :game_answers do |t|
|
||||
t.references :challenge_answer
|
||||
t.references :user
|
||||
t.references :game
|
||||
t.datetime :view_time
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddIndexForGameAnswers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_index :game_answers, [:challenge_answer_id, :user_id], :unique => true
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe GameAnswer, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue