Sha256: 08787fa3eee2cc96eeca46901b248c16b7e3560f2a3c1b3641f99c28068bc4f3
Contents?: true
Size: 755 Bytes
Versions: 5
Compression:
Stored size: 755 Bytes
Contents
module Scopes::Variant # WARNING tested only under sqlite and postgresql Variant.named_scope :descend_by_popularity, lambda{ { :order => 'COALESCE((SELECT COUNT(*) FROM line_items GROUP BY line_items.variant_id HAVING line_items.variant_id = variants.id), 0) DESC' } } # for selecting variants with an option value # no option type given since the value implies an option type # this scope can be chained repeatedly, since the join name is unique Variant.named_scope :has_option, lambda {|opt| tbl = 'o' + Time.now.to_i.to_s + Time.now.usec.to_s { :joins => "inner join option_values_variants as #{tbl} on variants.id = #{tbl}.variant_id", :conditions => ["#{tbl}.option_value_id = (?)", opt] } } end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
spree-0.11.4 | lib/scopes/variant.rb |
spree-0.11.3 | lib/scopes/variant.rb |
spree-0.11.2 | lib/scopes/variant.rb |
spree-0.11.1 | lib/scopes/variant.rb |
spree-0.11.0 | lib/scopes/variant.rb |