Sha256: 7a4d86bccaeae17e12e7054fa2b3bf8bbf3380b2b0a3523791a046e669cd1fdf

Contents?: true

Size: 695 Bytes

Versions: 1

Compression:

Stored size: 695 Bytes

Contents

module Theblog
  class ContentNode < ActiveRecord::Base
    belongs_to :content_status
    belongs_to :parent_node, class_name: 'Theblog::ContentNode'
    belongs_to :author, class_name: Incarnator.account_model

    has_many :child_nodes, class_name: 'Theblog::ContentNode', foreign_key: :parent_node_id

    validates_presence_of :title, :slug
    validates_uniqueness_of :slug, scope: :type

    scope :by_parent, ->(parent_slug) do
      if parent_slug.present?
        joins('JOIN theblog_content_nodes AS parents ON theblog_content_nodes.parent_node_id = parents.id').
          where(parents: {slug: parent_slug})
      else
        where(parent_node_id: nil)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
theblog-0.0.1.1 app/models/theblog/content_node.rb