Files
astuto/app/models/post.rb
Riccardo Graziosi dad382d2b1 Post follow and updates notifications V1 (#111)
* It is now possible to follow a post in order to receive updates about it
* Notifications are now sent when updates are published
* Post status changes are now tracked
* Update sidebar now shows the post status history
* Mark a comment as a post update using the comment form
* ... more ...
2022-05-28 11:03:36 +02:00

28 lines
773 B
Ruby

class Post < ApplicationRecord
belongs_to :board
belongs_to :user
belongs_to :post_status, optional: true
has_many :likes, dependent: :destroy
has_many :follows, dependent: :destroy
has_many :followers, through: :follows, source: :user
has_many :comments, dependent: :destroy
has_many :post_status_changes, dependent: :destroy
validates :title, presence: true, length: { in: 4..64 }
paginates_per Rails.application.posts_per_page
class << self
def find_with_post_status_in(post_statuses)
where(post_status_id: post_statuses.pluck(:id))
end
def search_by_name_or_description(s)
s = s || ''
s = sanitize_sql_like(s)
where("posts.title ILIKE ? OR posts.description ILIKE ?", "%#{s}%", "%#{s}%")
end
end
end