开发者

Converting from MySQL to Postgres and getting a 'column "Product" does not exist' error

开发者 https://www.devze.com 2023-04-04 05:25 出处:网络
I\'m using acts_as_taggable_on in rails and I\'m trying to get a listing of all Products that have yet开发者_JS百科 to be tagged.In MySQL the following query worked:

I'm using acts_as_taggable_on in rails and I'm trying to get a listing of all Products that have yet开发者_JS百科 to be tagged. In MySQL the following query worked:

  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"
    )

In Postgres, however, I get the error that the column "Product" does not exist.

The generated SQL appears to be:

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') ) 

Any suggestions on how to get this working? I'd prefer to use an active record friendly way so that it may still work in MySQL. But that's something I'd be willing to sacrifice.

Thanks in advance..


You should be quoting string literals with single quotes in PostgreSQL, not double quotes, double quotes are for quoting identifiers (such as table and column names). MySQL tends to play fast and loose with the standards, PostgreSQL tends to be much stricter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号