Commit 94f8a98f by ivan Lan

Allow series scope :query_spec_value_with_product

Allow series scope :query_spec_value_with_product to get spec_value which contain target value
parent 6a5e335b
......@@ -74,8 +74,8 @@ module Shotengai
Shotengai::Series.alive.find_by_id(default_series_id) || series.alive.first
end
def series_with_spec_value val
series_class.query_spec_value_with_product(val, self)
def series_with_spec_value val, eql=true
series_class.query_spec_value_with_product(val, self, eql)
end
def meta
......
......@@ -54,8 +54,8 @@ module Shotengai
scope :recycle_bin, ->{ unscope(where: :aasm_state).deleted.where('updated_at < ?', Time.now - 10.day )}
# where("spec->'$.\"颜色\"' = ? and spec->'$.\"大小\"' = ?" ,红色,S)
scope :query_spec_value_with_product, ->(val, product) {
if val.keys.sort == product.spec_template.keys.sort
scope :query_spec_value_with_product, ->(val, product, eql=true) {
if val.keys.sort == product.spec_template.keys.sort || (!.eql && (val.keys - product.spec_template.keys).empty?)
keys = []; values = [];
proc = Proc.new { |k, v| keys << "spec_value->'$.\"#{k}\"' = ? "; values << v }
Shotengai::Harray === val ? val.hash_map(&proc) : val.map(&proc)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment