Sha256: e198fc5ec0bb23417c32ff702ea0c38f962306ddfd6073c5b9efd3de1f9b7552

Contents?: true

Size: 535 Bytes

Versions: 1

Compression:

Stored size: 535 Bytes

Contents

module Cms9
  class PostDefinition < ApplicationRecord
    validates :name, presence: true, uniqueness: { case_sensitive: false },
              length: { minimum: 3 }

    has_many :post_fields, dependent: :destroy
    has_many :posts, dependent: :destroy


    def fields
      if @cache_fields.nil?
        @cache_fields = self.post_fields.map { |field| [field.name, field] }.to_h
      end

      @cache_fields.values
    end

    # Get field by name
    def field(name)
      fields()
      @cache_fields[name]
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cms9-0.2.0 app/models/cms9/post_definition.rb