Sha256: e2718e7e715825091cdfb304af69c4f4bd342933e16d55cbc36e1a0ece505e66

Contents?: true

Size: 589 Bytes

Versions: 5

Compression:

Stored size: 589 Bytes

Contents

class Order < ActiveRecord::Base
  belongs_to :client

  # search
  searchable_by_simple_filter

  scope :of_client_city, lambda {  |city| where_client_city(city) }

  def self.where_client_city(v)
    if v.present?
      where(client_id: Client.select("id").where(:city => v))
    else
      where("1=1")
    end
  end


  #
  scope :of_category, lambda {  |category_id| where_category(category_id) }

  def self.where_category(id)
    v = (id.to_i rescue 0)
    if v>0
      where(product_id: Product.select("id").where(:category_id => id))
    else
      where("1=1")
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_search_filter-0.2.1 test/dummy/app/models/order.rb
simple_search_filter-0.1.1 test/dummy/app/models/order.rb
simple_search_filter-0.1.0 test/dummy/app/models/order.rb
simple_search_filter-0.0.31 test/dummy/app/models/order.rb
simple_search_filter-0.0.30 test/dummy/app/models/order.rb