ruby-on-rails - 在 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
解决方案
推荐阅读
- visual-studio - 无法在虚拟机中运行的 Visual Studio 2019 中使用包管理器控制台
- jenkins-pipeline - Jenkinsfile 的 sshagent 块内的 Shell 变量
- php - php ftp_put 不适用于一个目录
- java - 发生 JNI 错误,请检查您的安装并重试。(尽管 Java -version 和 javac -version 也相同)
- python-3.x - 避免写入 pyspark 数据帧中存在的 NULL 字段
- sql - SQL SUM 忽略 NULL 值
- r - 将 col 转换为数据框列表中的行名
- python - Python 3 中的列表组合挑战
- java - Resilience4j 围绕尝试的方法返回 CompletableFuture
- amazon-web-services - AWS 和 CloudFormation:如何将虚拟私有网关附加到路由表?