ArgumentError: Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key
First of all, there is a question, which is almost similar to mine, but I cannot make it work for my code. So, I decided to ask separately.
This is where I get error:
has_many :friendships
has_many :friends,
:through => :friendships,
:conditions => "status = 'accepted'",
:order => :screen_name
has_many :requested_friends,
:through => :friendships,
:source => :friend,
:conditions => "status = 'requested'",
:order => :created_at
has_many :pending_friends,
:through => :friendships,
:source => :friend,
:conditions => "status = 'pending'",
:order => :created_at
I don't know if I should share some other of my codes to help you to understand. If you need some other parts, I can also paste them.
This is the full error:
Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type
Thank you.
EDIT
I fixed the problem:
has_many :friendships
has_many :friends, -> { where(friendship: {status: 'accepted'}).order('created_at') }, :through => :friendships
has_many :requested_friends, -> { where(friendship: {status: 'requested'}).order('created_at') }, :through => :friendships, :source => :friend
has_many :pending_friends, -> { where(friendship: {status: 'pending'}).order('created_at') }, :through => :friendships, :source => :friend
This is the error I am getting now:
Mysql2::Error: Unknown column 'friendship.status' in 'where clause': SELECT 1 AS one FROM `users` INNER JOIN `friendships` ON `users`.`id` = `friendships`.`friend_id` WHERE `friendships`.`user_id` = 6 AND `friendship`.`status` = 'requested' AND `users`.`id` = 8 LIMIT 1
This is where error occurs:
def accept # accept_request
if @user.requested_friends.include?(@friend)
Friendship.accept_request(@user, @friend)
end
redirect_to profile_path(params[:id])
end
Specifically here:
if @user.requested_friends.include?(@friend)
accept_request:
def self.accept_request(user, friend)
transaction do
accept_one_side(user, friend)
accept_one_side(friend, user)
end
end
accept_one_side:
private
def self.accept_one_side(user, friend)
request = find_by_user_id_and_friend_id(user, friend)
request.status = 'accepted'
request.save!
end