2
我试图从MySQL过渡到看起来更严格和更少的Rails友好的PostgreSQL。尽管只是增加ORDER BY vendors.id
作品就好了作为一个有效的PostgreSQL的查询事实ActiveRecord/Arel查询在试图订购时解决了一些奇怪的问题
irb(main):015:0> puts w.to_sql
SELECT DISTINCT ON (vendors.id) vendors.*
FROM "vendors"
INNER JOIN "locations" ON "locations"."locatable_id" = "vendors"."id"
AND "locations"."locatable_type" = 'Vendor'
WHERE (locations.latitude IS NOT NULL AND locations.longitude IS NOT NULL)
但是......
irb(main):017:0> puts w.order('vendors.id').to_sql
SELECT * FROM (
SELECT DISTINCT ON (vendors.id) vendors.*
FROM "vendors"
INNER JOIN "locations" ON "locations"."locatable_id" = "vendors"."id"
AND "locations"."locatable_type" = 'Vendor'
WHERE (locations.latitude IS NOT NULL AND locations.longitude IS NOT NULL)
) AS id_list ORDER BY id_list.alias_0
这:
我运行到这个有趣的难题。而不是仅仅补充说,它的东西超级搞笑,并在一天结束时产生的无效查询:
ActiveRecord::StatementInvalid: PGError: ERROR: column id_list.alias_0 does not exist
LINE 1: ...tions.longitude IS NOT NULL)) AS id_list ORDER BY id_list.al...
任何线索我应该看什么?