0

我在简历和教育之间有多对多的关系,这允许相同的教育条目出现在多份简历上。在简历上显示教育时,我希望为该特定简历订购教育。为此,我设置了一个连接表 Educations_Resumes,其中订单信息作为属性。

但是,当我尝试类似 resume.educations 时,我收到以下错误:

ActiveRecord::StatementInvalid: SQLite3::SQLException: near "order": syntax error: 
SELECT "educations".* FROM "educations" INNER JOIN "educations_resumes" ON 
"educations"."id" = "educations_resumes"."education_id" WHERE 
"educations_resumes"."resume_id" = 2 ORDER BY educations_resumes.order

模型设置为:

class Resume < ActiveRecord::Base
  has_many :educations_resumes
  has_many :educations, :through => :educations_resumes,
           :order => 'educations_resumes.order'

end

class EducationsResume < ActiveRecord::Base
  belongs_to :resume
  belongs_to :education
end

class Education < ActiveRecord::Base
  has_many :educations_resumes
  has_many :resumes, :through => :educations_resumes
end

任何有关如何正确订购 resume.educations 的建议将不胜感激

4

1 回答 1

0

您正在使用关键字作为列名:

http://www.sqlite.org/lang_keywords.html

运行迁移并更改列名:

rails g migration FixColumnName

这将为您提供一个空的迁移文件,您应该填写以下内容:

class FixColumnName < ActiveRecord::Migration
  def change
    rename_column :educations_resumes, :order, :ordering
  end
end
于 2013-03-19T02:13:36.173 回答