Sha256: 3dbfe2e34f6954e42f220e5992d73655df91729065933902ab8a436745c25ef0

Contents?: true

Size: 471 Bytes

Versions: 10

Compression:

Stored size: 471 Bytes

Contents

# frozen_string_literal: true

class Post < ApplicationRecord
  validates :title, presence: true, uniqueness: true
  validates :body, presence: true
  validates :category_id, presence: true

  belongs_to :category, inverse_of: :posts

  scope :published, -> { where "published_at <= date('now')" }
  scope :unpublished, -> { where "published_at IS NULL OR published_at > date('now')" }

  def published?
    published_at.present? && published_at < Time.current
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
search_object_graphql-1.0.5 example/app/models/post.rb
search_object_graphql-1.0.4 example/app/models/post.rb
search_object_graphql-1.0.3 example/app/models/post.rb
search_object_graphql-1.0.2 example/app/models/post.rb
search_object_graphql-1.0.1 example/app/models/post.rb
search_object_graphql-1.0.0 example/app/models/post.rb
search_object_graphql-0.3.2 example/app/models/post.rb
search_object_graphql-0.3.1 example/app/models/post.rb
search_object_graphql-0.3 example/app/models/post.rb
search_object_graphql-0.2 example/app/models/post.rb