【问题标题】:ArgumentError: Unknown key: :order. Valid keys are: :class_name, :anonymous_class in Rails 4.2.6ArgumentError:未知键::order。有效键是:Rails 4.2.6 中的 :class_name, :anonymous_class
【发布时间】:2016-11-02 08:25:02
【问题描述】:

运行 rake db:migrate 时出现以下错误:

ArgumentError: Unknown key: :order.有效键是::class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type

这是我遇到错误的模型:

class Report < ActiveRecord::Base

  belongs_to :user
  has_many :icons, :order => 'position_id ASC' #showing error here..
  has_many :photos, :dependent => :destroy

end

请帮忙。

【问题讨论】:

标签: ruby-on-rails


【解决方案1】:
has_many :icons, -> { order('position_id ASC') }

【讨论】:

    【解决方案2】:

    Duplicate

    has_many :icons, -&gt; { order('position_id ASC') } #showing error here..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      相关资源
      最近更新 更多