【问题标题】:Rails: Scoped association resulting in error [duplicate]Rails:范围关联导致错误[重复]
【发布时间】:2018-01-01 07:01:49
【问题描述】:

在一个模型中,我有以下范围关联:

customer.rb:38

has_many :payment_informations, class_name: 'Customer::PaymentInformation', dependent: :destroy, -> { order(position: :asc) }

错误:

语法错误,意外 '\n',期待 =>

--

我在这里做错了什么?该错误仅在确定关联范围时发生。

【问题讨论】:

    标签: ruby-on-rails ruby scope associations ruby-on-rails-5


    【解决方案1】:

    试试

    has_many :payment_informations, -> { order(position: :asc) }, class_name: 'Customer::PaymentInformation', dependent: :destroy
    

    【讨论】:

    • 嗯...... :)
    【解决方案2】:
    has_many(name, scope = nil, options = {}, &extension)
    

    这是 has_many 期望的顺序。

    【讨论】:

    • 感谢您的解释!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 2016-07-23
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多