class JournalsForMessage < ApplicationRecord belongs_to :jour, :polymorphic => true belongs_to :user belongs_to :parent, class_name: "JournalsForMessage", foreign_key: "m_parent_id", counter_cache: :m_reply_count, optional: true has_many :praise_treads, as: :praise_tread_object, dependent: :destroy #scope :children, -> {where(m_parent_id: self.id).includes(:user).reorder("created_on asc")} #scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder("created_at asc") } scope :parent_comment, -> { where(m_parent_id: nil)} scope :search_by_jour_type, lambda{|type,ids| where(jour_type:type,jour_id: ids)} # "jour_type", # 留言所属类型 # "jour_id", # 留言所属类型的id # "notes", # 留言内容 # "reply_id", # 留言被回复留言者的用户id(用户a回复了用户b,这是b的id,用以查询谁给b留言了) # "status", # 留言是否被查看(弃用) # "user_id", # 留言者的id # "m_parent_id", # 留言信息的父留言id # "is_readed", # 留言是否已读 # "m_reply_count", # 留言的回复数量 # "m_reply_id" , # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) # "is_comprehensive_evaluation", # 1 教师评论、2 匿评、3 留言 # "hidden", 隐藏 # course_identity 课堂用户身份 def contents_show course_identity if self.hidden && course_identity >= Course::STUDENT nil else self.notes end end def can_delete course_identity course_identity < Course::STUDENT end def created_at self.created_on end def children page, limit JournalsForMessage.includes(:user).where(m_parent_id: self.id).page(page).per(limit).reorder("created_on asc") end end