2011-05-05 5 views
0

여기 내 사용자 모델은 다음과 같습니다.자체 참조는 has_many, : through

class User < ActiveRecord::Base 

    has_many :friends, :class_name => 'Friendship', :dependent => :destroy 

end 

내 우정 모델은 다음과 같습니다.

class Friendship < ActiveRecord::Base 

    belongs_to :user 
    belongs_to :friend, :class_name => 'User', :foreign_key => 'friend_id' 

    set_table_name :users_users 
end 

이제 사용자 모델에 * is_awesome *이라는 부울 속성이 있습니다.

User.find(1).friends.find(:all, :include => :users, :conditions => {:is_awesome => false}) 

다음과 같은 오류가 발생합니다.

ActiveRecord::StatementInvalid: Mysql::Error: 
Unknown column 'users_users.is_awesome' in 'where clause': 
SELECT * FROM `users_users` 
WHERE (`users_users`.user_id = 1 AND (`users_users`.`is_awesome` = 0)) 

어떤 일이 벌어지고 있는지 알 수 있습니까?

+0

우정 모델의 실제 테이블 이름이 데이터베이스에 users_users입니다 : 조건을 사용자 테이블을 참조, 그것은해야 다음과 같이 보입니다. – keruilin

답변

0

당신은 변경해야합니다 :

User.find(1).friends.find(:all, :include => :users, :conditions => "users.is_awesome IS FALSE") 
관련 문제