我在简历和学历之间有一种多对多的关系,允许同一学历条目出现在多份简历上。在简历上显示学历信息时,我希望为该特定简历订购学历信息。为此,我设置了一个连接表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的建议都将不胜感激
发布于 2013-03-19 10:13:36
您正在使用关键字作为列名:
http://www.sqlite.org/lang_keywords.html
运行迁移并更改列名:
rails g migration FixColumnName这将为您提供一个空的迁移文件,您应该使用以下内容填充该文件:
class FixColumnName < ActiveRecord::Migration
def change
rename_column :educations_resumes, :order, :ordering
end
endhttps://stackoverflow.com/questions/15490371
复制相似问题