首页 > 解决方案 > 在 Spree 中查找产品的卖家

问题描述

我正在使用spree,我的ruby技能对我没有帮助。每个产品都有一个product property,其中属性命名为:Seller

这是模型图:

Product has many ProductProperty

ProductProperty belongs_to Property

Product has many Property through ProductProperty

我想做Product.includes(:seller),卖家在ProductProperty哪里Property.name = 'Seller'

我的错误尝试现在是:

base.has_one :seller, -> { joins(:properties).where(spree_properties: {name: 'Seller'}) }, inverse_of: :product, class_name: 'Spree::ProductProperty'

编辑:如果代码有效,示例查询:

SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."deleted_at" IS NULL AND "spree_products"."id" = $1 LIMIT $2
SELECT "spree_product_properties".* FROM "spree_product_properties" INNER JOIN "spree_properties" ON "spree_properties"."id" = "spree_product_properties"."property_id" WHERE "spree_product_properties"."product_id" in [$1] AND "spree_properties"."name" = $2

标签: ruby-on-railsrubyspree

解决方案


推荐阅读