Not doing so has a few gotchas when working with relations, particularly with records which are not stored in the database. I'm excluding the related content file because it's got a very peculiar relationship with itself: the `has_one :opposite_related_content` has no inverse; the relation itself is its inverse. It's a false positive since the inverse condition is true: ``` content.opposite_related_content.opposite_related_content.object_id == content.object_id ```
19 lines
598 B
Ruby
19 lines
598 B
Ruby
class Topic < ApplicationRecord
|
|
acts_as_paranoid column: :hidden_at
|
|
include ActsAsParanoidAliases
|
|
include Notifiable
|
|
|
|
belongs_to :community
|
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :topics
|
|
|
|
has_many :comments, as: :commentable, inverse_of: :commentable
|
|
|
|
validates :title, presence: true
|
|
validates :description, presence: true
|
|
validates :author, presence: true
|
|
|
|
scope :sort_by_newest, -> { order(created_at: :desc) }
|
|
scope :sort_by_oldest, -> { order(created_at: :asc) }
|
|
scope :sort_by_most_commented, -> { reorder(comments_count: :desc) }
|
|
end
|