Add `pinned_at` to answers
This commit is contained in:
parent
5579489a92
commit
c2baa86c09
|
@ -14,6 +14,8 @@ class Answer < ApplicationRecord
|
|||
validates :question_id, uniqueness: { scope: :user_id }
|
||||
# rubocop:enable Rails/UniqueValidationWithoutIndex
|
||||
|
||||
scope :pinned, -> { where.not(pinned_at: nil) }
|
||||
|
||||
SHORT_ANSWER_MAX_LENGTH = 640
|
||||
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
|
@ -56,4 +58,6 @@ class Answer < ApplicationRecord
|
|||
end
|
||||
|
||||
def long? = content.length > SHORT_ANSWER_MAX_LENGTH
|
||||
|
||||
def pinned? = pinned_at.present?
|
||||
end
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPinnedAtToAnswers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :answers, :pinned_at, :timestamp
|
||||
add_index :answers, %i[user_id pinned_at]
|
||||
end
|
||||
end
|
|
@ -48,8 +48,10 @@ ActiveRecord::Schema.define(version: 2023_02_12_181044) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "smile_count", default: 0, null: false
|
||||
t.datetime "pinned_at"
|
||||
t.index ["question_id"], name: "index_answers_on_question_id"
|
||||
t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
|
||||
t.index ["user_id", "pinned_at"], name: "index_answers_on_user_id_and_pinned_at"
|
||||
end
|
||||
|
||||
create_table "appendables", force: :cascade do |t|
|
||||
|
|
Loading…
Reference in New Issue