Amr*_*ana 5 ruby-on-rails-4 ruby-2.1
我有这个问题
has_many :unused_invitations, :class_name => 'Invitation', :foreign_key => 'inviter_id', :conditions => 'used = false'
Run Code Online (Sandbox Code Playgroud)
我使用的是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'
Run Code Online (Sandbox Code Playgroud)
我通过修改查询来解决它
has_many :used_invitations, class_name: 'Invitation', foreign_key: 'inviter_id', -> { where used: false}
Run Code Online (Sandbox Code Playgroud)
但我仍然得到语法错误
syntax error, unexpected '\n', expecting => (SyntaxError)
Run Code Online (Sandbox Code Playgroud)
查询有什么问题?有人会解释我的吗?我已经回答了这个问题,但找不到答案.
通过更新查询解决此问题
has_many :used_invitations, -> { where used: false}, class_name: 'Invitation', foreign_key: 'inviter_id'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2616 次 |
| 最近记录: |