在此应用程序中,模型 Resource_Estimations 由公司完成。我希望对公司名称的 Resource_Estimations 有一个默认排序顺序。
公司模式
class Company < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
...
has_many :resource_estimations, dependent: :destroy
...
validates :exchange_id, :name, :full_name, presence: true
资源_估计模型
class ResourceEstimation < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
...
belongs_to :company
...
validates :company_id, :drill_id, :resource_type_id, :date,
:fill_to_spill,:p10, :p50, :p90, presence: true
...
default_scope { order(:company => :asc) }
Resource_Estimation 模型中的最后一条语句(default_scope)是我想要改变的。我希望排序顺序是 company.name,而不是 company_id 的当前排序顺序。已经尝试了很多东西,但到目前为止没有运气。欢迎任何建议 - 谢谢皮埃尔