5

我有这个查询

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)

查询有什么问题?有人会解释一下吗。我已经解决了这个问题,但找不到答案。

4

1 回答 1

2

通过更新查询解决此问题

has_many :used_invitations, -> { where used: false}, class_name: 'Invitation', foreign_key: 'inviter_id'
于 2014-03-17T07:32:06.787 回答