Sha256: 584ea412598f50c611c602eedd77f9b9e9d6f945da5ef8a5a1349b39f08cabdb

Contents?: true

Size: 866 Bytes

Versions: 4

Compression:

Stored size: 866 Bytes

Contents

class Comfy::Blog::Blog < ActiveRecord::Base
  
  self.table_name = 'comfy_blogs'
  
  # -- Relationhips ---------------------------------------------------------
  belongs_to :site, :class_name => 'Comfy::Cms::Site'
  
  has_many :posts,
    :dependent  => :destroy
  has_many :comments,
    :through    => :posts
    
  # -- Validations ----------------------------------------------------------
  validates :site_id, :label, :identifier,
    :presence   => true
  validates :identifier,
    :format     => { :with => /\A\w[a-z0-9_-]*\z/i }
  validates :path,
    :uniqueness => { :scope => :site_id },
    :format     => { :with => /\A\w[a-z0-9_-]*\z/i },
    :presence   => true,
    :if         => 'restricted_path?'
  
protected

  def restricted_path?
    (self.class.count > 1 && self.persisted?) ||
    (self.class.count >= 1 && self.new_record?)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
comfy_blog-1.12.3 app/models/comfy/blog/blog.rb
comfy_blog-1.12.2 app/models/comfy/blog/blog.rb
comfy_blog-1.12.1 app/models/comfy/blog/blog.rb
comfy_blog-1.12.0 app/models/comfy/blog/blog.rb