Sha256: af0f2ae3386a617c52bf6985b9aa8376b23c5ae5fa34b5f5171bd737b52933ef

Contents?: true

Size: 698 Bytes

Versions: 1

Compression:

Stored size: 698 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 app/models/theblog/content_node.rb