我在 rails 中使用acts_as_taggable_on 并且试图获取所有尚未标记的产品的列表。在 MySQL 中,以下查询有效:
def self.untagged
available.find(:all,
:joins => %{LEFT JOIN taggings ON products.id = taggings.taggable_id AND taggings.taggable_type = "Product"},
:conditions => "taggings.id IS NULL AND for_sale IS true",
:order => "products.updated_at DESC"
)
但是,在 Postgres 中,我收到“产品”列不存在的错误。
生成的 SQL 似乎是:
SELECT count(*) AS count_all FROM "products" LEFT JOIN taggings ON products.id = taggings.taggable_id AND taggings.taggable_type = "Product" WHERE (taggings.id IS NULL AND for_sale IS true) AND (products.date_expires > '2011-09-12') )
关于如何使它工作的任何建议?我更喜欢使用主动记录友好的方式,以便它仍然可以在 MySQL 中工作。但这是我愿意牺牲的。
提前致谢..