class Info < ApplicationRecord
  belongs_to :user
  has_many :comments, dependent: :destroy

  validates :user_id, presence: true

  default_scope -> { order(created_at: :desc) }
  scope :not_archived, -> { where(archived: false).order(created_at: :desc) }
  scope :archived, -> { where(archived: true).order(created_at: :desc) }
  
  validates :title, presence: true
  validates :content, presence: true
end

class Info < ApplicationRecord
  belongs_to :user
  has_many :comments, dependent: :destroy

  validates :user_id, presence: true

  default_scope -> { includes(:user).order(created_at: :desc) }
  scope :not_archived, -> { includes(:user, :comments)
                            .where(archived: false)
                            .order(created_at: :desc)
                          }
  scope :archived, -> { includes(:user, :comments)
                        .where(archived: true)
                        .order(created_at: :desc)
                      }
  
  validates :title, presence: true
  validates :content, presence: true
end

Improve DB calls in scopes
Improve DB calls in scopes
