Skip to content
Browse files

Refactor variant_images to return a scope, not an Array

Conflicts:

	core/app/models/spree/product.rb
  • Loading branch information...
1 parent cbf20f5 commit 77df79cf7ea61a80b4ec7cd16ada8066ca70238f @radar radar committed May 11, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 core/app/models/spree/product.rb
View
5 core/app/models/spree/product.rb
@@ -59,8 +59,9 @@ class Product < ActiveRecord::Base
accepts_nested_attributes_for :variants, :allow_destroy => true
def variant_images
- return [] if self.new_record? # newly created record?
- Image.find_by_sql("SELECT #{Asset.quoted_table_name}.* FROM #{Asset.quoted_table_name} LEFT JOIN #{Variant.quoted_table_name} ON (#{Variant.quoted_table_name}.id = #{Asset.quoted_table_name}.viewable_id) WHERE (#{Variant.quoted_table_name}.product_id = #{self.id}) ORDER BY #{Asset.quoted_table_name}.position")
+ Image.joins("LEFT JOIN #{Variant.quoted_table_name} ON #{Variant.quoted_table_name}.id = #{Asset.quoted_table_name}.viewable_id").
+ where("#{Variant.quoted_table_name}.product_id = #{self.id}").
+ order("#{Asset.quoted_table_name}.position")
end
alias_method :images, :variant_images

0 comments on commit 77df79c

Please sign in to comment.
Something went wrong with that request. Please try again.