I have a many-to-many relation between Resumes and Educations which allows for the same education entry to appear on multiple resumes. When displaying Educations on a resume, I want the Educations to be ordered for that specific resume. To do this I set up a join table, Educations_Resumes, with the order information as a property.
我在简历和教育之间有多对多的关系,允许相同的教育条目出现在多个简历中。在简历上显示教育时,我希望为特定的简历订购教育。为此,我设置了一个连接表Educations_Resumes,其中包含订单信息作为属性。
However, when I try some like resume.educations I get the following error:
但是,当我尝试一些像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
The models are setup as:
模型设置为:
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
Any suggestions on how to correctly order resume.educations would be greatly appreciated
任何关于如何正确订购resume.educations的建议将不胜感激
1 个解决方案
#1
0
You are using a keyword as a column name:
您使用关键字作为列名:
http://www.sqlite.org/lang_keywords.html
http://www.sqlite.org/lang_keywords.html
Run a migration and change the column name:
运行迁移并更改列名称:
rails g migration FixColumnName
This will give you a empty migration file that you should fill in with something like:
这将为您提供一个空的迁移文件,您应该填写以下内容:
class FixColumnName < ActiveRecord::Migration
def change
rename_column :educations_resumes, :order, :ordering
end
end
#1
0
You are using a keyword as a column name:
您使用关键字作为列名:
http://www.sqlite.org/lang_keywords.html
http://www.sqlite.org/lang_keywords.html
Run a migration and change the column name:
运行迁移并更改列名称:
rails g migration FixColumnName
This will give you a empty migration file that you should fill in with something like:
这将为您提供一个空的迁移文件,您应该填写以下内容:
class FixColumnName < ActiveRecord::Migration
def change
rename_column :educations_resumes, :order, :ordering
end
end