Soc/app/models/learning_goal.rb

22 lines
632 B
Ruby
Raw Normal View History

2024-01-06 09:42:36 +00:00
class LearningGoal < ApplicationRecord
belongs_to :user
2024-01-07 13:50:53 +00:00
has_many :todos
has_and_belongs_to_many :tags
accepts_nested_attributes_for :tags
2024-01-06 09:42:36 +00:00
2024-01-06 10:29:41 +00:00
has_rich_text :description
has_rich_text :retrospective
2024-01-07 13:22:21 +00:00
validates :completed, inclusion: { in: [true, false] }
2024-01-06 09:42:36 +00:00
validates :title, presence: true
2024-01-06 11:10:56 +00:00
2024-01-07 14:17:47 +00:00
scope :current, -> { where(starts_on: ..Date.today, ends_on: Date.today..) }
scope :past, -> { where(ends_on: ..Date.today) }
scope :future, -> { where(starts_on: Date.today..) }
def microposts
microposts = Micropost.none
tags.each { |tag| microposts = microposts.or(tag.microposts) }
2024-01-07 13:50:53 +00:00
microposts.uniq
end
2024-01-06 09:42:36 +00:00
end