复杂关联中ID的特定顺序

时间:2014-09-24 01:54:00

标签: ruby-on-rails ruby-on-rails-3

候选人申请job。他的申请是matching,可以在面试过程中设置为任何stage

协会

# matching.rb
has_one :matching_stage
has_one :stage, through: :matching_stage
belongs_to everything else

# matching_stage.rb
belongs_to :matching
belongs_to :stage

# stage.rb
has_many :matchings, through: :matching_stage
has_many :matching_stages

问题

我有一个数组:@ordered_stage_ids = [2, 5, 6, 1, 17, 5]

我需要编写一个返回@matchings的查询,以便根据@matching.matching_stage.stage_id数组对@ordered_stage_ids进行排序。

尝试

@matchings = @job.matchings.submitted.unrejected
  .includes(:matching_stage).order('matching_stage.stage_id', @ids)

这似乎有效,但后来我收到了错误:

@matchings.each do |m|

ActionView::Template::Error (PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "matching_stage"
LINE 1: ...) AND (matchings.employer_rejects = 'f') ORDER BY matching_s...

0 个答案:

没有答案