spree-contrib / spree_related_products

Related products extension for Spree Commerce.
http://guides.spreecommerce.org
BSD 3-Clause "New" or "Revised" License
149 stars 241 forks source link

product.{{relation_type}} returns nil in the array #75

Closed justame closed 10 years ago

justame commented 10 years ago

The version that i work with is 2.1.

to reproduce the bug , associate to a product 2 products, first product is not available("AVAILABLE ON" is empty) and the second will be available the relation type name is "color" in the console in goes likes that :

[96] pry(main)> product = Spree::Product.find  7
  Spree::Product Load (4.0ms)  SELECT "spree_products".* FROM "spree_products" WHERE ("spree_products".deleted_at IS NULL) AND "spree_products"."id" = $1 LIMIT 1  [["id", 7]]
=> #<Spree::Product id: 7, name: "אלקטרה בר אדום רימון-24חו", description: "", available_on: nil, deleted_at: nil, permalink: "lqtrh-br-dvm-rymvn-24khv", meta_description: "", meta_keywords: "", tax_category_id: nil, shipping_category_id: 1, created_at: "2013-11-21 17:38:13", updated_at: "2013-11-24 14:17:28", bullet1: "", bullet2: "", bullet3: "">

[98] pry(main)> product.relations
=> [#<Spree::Relation id: 1, relation_type_id: 1, relatable_id: 7, relatable_type: "Spree::Product", related_to_id: 4, related_to_type: "Spree::Product", created_at: "2013-11-24 16:20:18", updated_at: "2013-11-24 16:28:47", discount_amount: #<BigDecimal:c7f3bfc,'0.11E2',9(18)>, position: nil>,
 #<Spree::Relation id: 2, relation_type_id: 1, relatable_id: 7, relatable_type: "Spree::Product", related_to_id: 5, related_to_type: "Spree::Product", created_at: "2013-11-24 16:20:28", updated_at: "2013-11-24 16:28:47", discount_amount: #<BigDecimal:c7f2e3c,'0.11E2',9(18)>, position: nil>]

[101] pry(main)> product.colors
DEPRECATION WARNING: This dynamic method is deprecated. Please use e.g. Post.where(...).all instead. (called from relation_types at /home/yaron/.rvm/gems/ruby-2.0.0-p247@payngo/bundler/gems/spree_related_products-0d84c715cca8/app/models/spree/product_decorator.rb:6)
  Spree::RelationType Load (0.5ms)  SELECT "spree_relation_types".* FROM "spree_relation_types" WHERE "spree_relation_types"."applies_to" = 'Spree::Product' ORDER BY "spree_relation_types"."name" ASC
   (0.2ms)  SELECT "spree_relations"."related_to_id" FROM "spree_relations" WHERE "spree_relations"."relatable_id" = $1 AND "spree_relations"."relatable_type" = $2 AND "spree_relations"."relation_type_id" = 1 ORDER BY "spree_relations"."position" ASC  [["relatable_id", 7], ["relatable_type", "Spree::Product"]]
DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. (called from relations_for_relation_type at /home/yaron/.rvm/gems/ruby-2.0.0-p247@payngo/bundler/gems/spree_related_products-0d84c715cca8/app/models/spree/product_decorator.rb:75)
  Spree::Product Load (0.5ms)  SELECT "spree_products".* FROM "spree_products" WHERE ("spree_products".deleted_at IS NULL) AND "spree_products"."id" IN (4, 5) AND "spree_products"."deleted_at" IS NULL AND (spree_products.available_on IS NOT NULL) AND (spree_products.available_on <= '2013-11-24 16:53:29.930488')
=> [#<Spree::Product id: 4, name: "אלקטרה בר קרם שמנת-24חודש", description: "", available_on: "2013-11-18 00:00:00", deleted_at: nil, permalink: "lqtrh-br-qrm-shmnt-24khvdsh", meta_description: "", meta_keywords: "", tax_category_id: nil, shipping_category_id: 1, created_at: "2013-11-21 17:35:55", updated_at: "2013-11-24 16:39:37", bullet1: "", bullet2: "", bullet3: "">,
 nil]

product.colors return nil in the array and it shouldn't.

radar commented 10 years ago

Hi @justame, do you have some code that quickly sets up these relationships so that I can try to reproduce your problem?

huoxito commented 10 years ago

@justame could you please try updating to latest 2-1-stable and confirm the patch above works for you?