首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >多对多关系中的Order by连接表属性

多对多关系中的Order by连接表属性
EN

Stack Overflow用户
提问于 2013-03-19 10:10:32
回答 1查看 298关注 0票数 0

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

然而,当我尝试像resume.educations这样的命令时,我得到了以下错误:

代码语言:javascript
运行
复制
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

模型设置为:

代码语言:javascript
运行
复制
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的建议都将不胜感激

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-19 10:13:36

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

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

运行迁移并更改列名:

代码语言:javascript
运行
复制
rails g migration FixColumnName

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

代码语言:javascript
运行
复制
class FixColumnName < ActiveRecord::Migration
  def change
    rename_column :educations_resumes, :order, :ordering
  end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15490371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档