按位置错误排序

时间:2017-07-13 11:08:41

标签: ruby-on-rails postgresql

我们已经使用Postgres数据库创建了一个关于Rails的查询,我们希望课程按位置按顺序排列为数组中可用的数据,在我们的例子中是course_ids。 course_ids数组包含sodes中的课程ID。

Course.includes(:course_series).
  where("course_id IN (?)", course_ids).
  order("position(course_id::text in '?')", course_ids.join(',')).
  order('course_name asc')

但显示错误

ActiveRecord::StatementInvalid in FrontendController#get_courses

PG::InvalidColumnReference: ERROR:  ORDER BY position 52 is not in select list
LINE 1: ...9)) ORDER BY position(course_id::text in '?'), 11,52, course...
                                                             ^
: SELECT "at_courses".* FROM "at_courses" WHERE "at_courses"."deleted_at" IS NULL AND (course_id IN (52,11)) ORDER BY position(course_id::text in '?'), 52,11, course_name asc
Extracted source (around line #598):

你能否分享一下这里出了什么问题?请放轻松我。我不是技术人员。

谢谢!

0 个答案:

没有答案
相关问题