【发布时间】:2019-04-12 11:04:49
【问题描述】:
假设我有一个instructions 表,它通过survey_instructions 连接表与surveys 表相关联。
我需要实现的是获取所有指令记录,但由关联存在与给定调查排序。
因此,与给定调查相关的说明将首先执行,然后是与此调查无关的所有其他说明。
class Instruction < ApplicationRecord
has_many :survey_instructions, dependent: :destroy
has_many :surveys, through: :survey_instructions
and
class Survey < ApplicationRecord
has_many :survey_instructions, dependent: :destroy
has_many :instructions, through: :survey_instructions
and
class SurveyInstruction < ApplicationRecord
belongs_to :survey
belongs_to :instruction
and
这可以通过以某种方式链接活动记录查询来实现吗?希望对此有任何想法
【问题讨论】:
标签: sql ruby-on-rails postgresql activerecord ruby-on-rails-5