Sha256: deca9e64fc9ae52f5577abca460d62bfea6fa41162bbe983cd8e226c8c350a91

Contents?: true

Size: 780 Bytes

Versions: 6

Compression:

Stored size: 780 Bytes

Contents

module LatoBlog
  class CategoryPost < ApplicationRecord

    # Validations:

    validates :lato_blog_category_id, presence: true
    validates :lato_blog_post_id, presence: true

    # Relations:

    belongs_to :category, foreign_key: :lato_blog_category_id, class_name: 'LatoBlog::Category'

    belongs_to :post, foreign_key: :lato_blog_post_id, class_name: 'LatoBlog::Post'

    # Callbacks:

    before_save do
      check_relation_language
    end

    after_save do
      blog__sync_config_post_fields_with_db_post_fields_for_post(post)
    end

    private

    def check_relation_language
      if self.category.meta_language != self.post.meta_language
        errors.add('Category and Post', 'have not same language')
        throw :abort
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lato_blog-2.2.2 app/models/lato_blog/category_post.rb
lato_blog-2.2.1 app/models/lato_blog/category_post.rb
lato_blog-2.2.0 app/models/lato_blog/category_post.rb
lato_blog-2.1.2 app/models/lato_blog/category_post.rb
lato_blog-2.1.1 app/models/lato_blog/category_post.rb
lato_blog-2.1 app/models/lato_blog/category_post.rb