argumenterror: unknown key: :conditions. valid keys are: :class_name, :class, :foreign_key
first of all, there question, similar mine, cannot make work code. so, decided ask separately.
this 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 should share other of codes understand. if need other parts, can paste them.
this 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 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 error getting now:
mysql2::error: unknown column 'friendship.status' in 'where clause': select 1 one `users` inner join `friendships` on `users`.`id` = `friendships`.`friend_id` `friendships`.`user_id` = 6 , `friendship`.`status` = 'requested' , `users`.`id` = 8 limit 1
this 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 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
problem fixed
problem in has_many.
this correct version:
has_many :friendships has_many :friends, -> { where(friendships: {status: 'accepted'}).order('created_at') }, :through => :friendships has_many :requested_friends, -> { where(friendships: {status: 'requested'}).order('created_at') }, :through => :friendships, :source => :friend has_many :pending_friends, -> { where(friendships: {status: 'pending'}).order('created_at') }, :through => :friendships, :source => :friend
it may same code above not.
because in first code, wrote: "where(friendship:" supposed be: "where(friendships:" so, forgot put 's'
Comments
Post a Comment