【发布时间】:2014-04-22 07:44:00
【问题描述】:
我有这个问题
has_many :unused_invitations, :class_name => 'Invitation', :foreign_key => 'inviter_id', :conditions => 'used = false'
我使用的是 rails 3.2.17,现在我正在升级到 rails 4.0.4。我收到了这个错误
DEPRECATION WARNING: The following options in your User.has_many :unused_invitations declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
我通过修改查询来解决
has_many :used_invitations, class_name: 'Invitation', foreign_key: 'inviter_id', -> { where used: false}
但我仍然遇到语法错误
syntax error, unexpected '\n', expecting => (SyntaxError)
查询有什么问题?有人会解释一下吗。我已经去了this 的问题,但找不到答案。
【问题讨论】: