我是 Rails 新手,所以如果它很愚蠢,请原谅这个问题:S
我使用 Spree 作为我选择的电子商务平台。
在 Rails 控制台中,我运行:
Spree::Product.joins(:product_properties, :taxons, :variants).limit(10)
这将返回 sql:
SELECT `spree_products`.* FROM `spree_products` INNER JOIN `spree_product_properties` ON `spree_product_properties`.`product_id` = `spree_products`.`id` INNER JOIN `spree_products_taxons` ON `spree_products_taxons`.`product_id` = `spree_products`.`id` INNER JOIN `spree_taxons` ON `spree_taxons`.`id` = `spree_products_taxons`.`taxon_id` INNER JOIN `spree_variants` ON `spree_variants`.`product_id` = `spree_products`.`id` AND `spree_variants`.is_master = 0 AND `spree_variants`.deleted_at IS NULL LIMIT 10
但是,我需要 sql 来设置值
`spree_variants`.is_master = 1 AND `spree_variants`.deleted_at IS NOT NULL
有人知道该怎么做吗?我努力了
Spree::Product.joins(:product_properties, :taxons, :variants).limit(10).where("`spree_variants`.is_master = 1 AND `spree_variants`.deleted_at IS NOT NULL")
但这不起作用并生成以下sql
SELECT `spree_products`.* FROM `spree_products` INNER JOIN `spree_product_properties` ON `spree_product_properties`.`product_id` = `spree_products`.`id` INNER JOIN `spree_products_taxons` ON `spree_products_taxons`.`product_id` = `spree_products`.`id` INNER JOIN `spree_taxons` ON `spree_taxons`.`id` = `spree_products_taxons`.`taxon_id` INNER JOIN `spree_variants` ON `spree_variants`.`product_id` = `spree_products`.`id` AND `spree_variants`.is_master = 0 AND `spree_variants`.deleted_at IS NULL WHERE (`spree_variants`.is_master = 1 AND `spree_variants`.deleted_at IS NOT NULL) LIMIT 10
谢谢!