5

I have this query

has_many :unused_invitations, :class_name => 'Invitation', :foreign_key => 'inviter_id', :conditions => 'used = false'

I was using rails 3.2.17 and now I am upgrading to rails 4.0.4. I got this error

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'

I solve it by modifying query

has_many :used_invitations, class_name: 'Invitation', foreign_key: 'inviter_id', -> { where used: false}

But Still I getting syntax error

syntax error, unexpected '\n', expecting => (SyntaxError)

What is wrong with query ? Will someone explain me about it. I have go this question but can't find the answer.

Community
  • 1
  • 1
Amrit Dhungana
  • 4,371
  • 5
  • 31
  • 36

1 Answers1

2

Solve this problem by updating the query

has_many :used_invitations, -> { where used: false}, class_name: 'Invitation', foreign_key: 'inviter_id'
Amrit Dhungana
  • 4,371
  • 5
  • 31
  • 36