当用户登陆页面时,我会打电话:
@objects = Object.select("objects.*, MAX(votes.updated_at) AS
mv").joins(:votes).group("objects.id").
order("mv DESC").includes(:categories)
这很好用。
但是,我有一个用于排序的 ajax 调用,当它调用完全相同的命令时,我遇到了一个错误,提示“mv 不是列”,这是查询:
SELECT COUNT(*) AS count_all, objects.id AS objects_id FROM "objects"
INNER JOIN "votes" ON "votes"."object_id" = "objects"."id"
GROUP BY objects.id ORDER BY mv DESC
为什么相同的命令完全忽略了 select 调用。它只用 count_all 和 objects_id 替换它?