2013-03-19 128 views
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任何建议将不胜感激

回答

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 
+0

谢谢!我无法相信我忽略了这样的事情。 – CodyAustun 2013-03-19 03:06:55

+0

没问题,我真的很高兴能够帮助你,并且首先对一些敏感的答案感到抱歉,我必须学会更好地阅读,但事实上,当你看到你的名字时,你命名列'order'有点让我无法理解代码:)祝你好运! – Zippie 2013-03-19 03:09:55

相关问题