ArgumentError: Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key

后端 未结 1 504
孤街浪徒
孤街浪徒 2021-01-18 02:49

After trying to rake:db migrate, I got this error in the terminal

rake aborted!
ArgumentError: Unknown key: :conditions. Valid keys are: :class_name, :class,         


        
相关标签:
1条回答
  • 2021-01-18 03:15

    You should change the code in User model to

    class User < ActiveRecord::Base
      has_many :user_friendships
      has_many :friends, -> { where(user_friendships: { state: "accepted"}) }, through: :user_friendships
      has_many :pending_user_friendships, -> { where(state: "pending") }, class_name: 'UserFriendship', foreign_key: :user_id                                  
      has_many :pending_friends, through: :pending_user_friendships, source: :friend
    end
    
    0 讨论(0)
提交回复
热议问题