Sha256: bfca8c142a3d1166d8b26a24f39de4f654ad6a8fcee4b1f9d427cb2a5b246891

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

# == Schema Information
#
# Table name: formats_categories
#
#  id                       :integer          not null, primary key
#  title_translations       :hstore           default({})
#  description_translations :hstore           default({})
#  service_id               :integer
#  created_at               :datetime
#  updated_at               :datetime
#
module Formats
  class Category < ActiveRecord::Base
    belongs_to :service, class_name: 'Formats::Service'
    has_many :items, class_name: 'Formats::Item', dependent: :destroy

    translates :title, :description

    scope :normal, -> { where.not(id: Formats::Service.pluck(:default_category_id)) }

    accepts_nested_attributes_for :items, allow_destroy: true

    class << self
      def sunrise_search(params)
        q = normal
        q = q.where('title LIKE ?', "%#{params[:title]}%") if params[:title].present?
        q = q.where(service_id: params[:service_id]) if params[:service_id].present?
        q
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/models/formats/category.rb