2014-02-27 3 views
0

나는 현재 모델로 참조하는 has_many 절에 조건을 가지고 노력하고있어하지만 난 오류가 받고 있어요에 조건 has_many는 :레일 : 자기

:

PG::Error: ERROR: missing FROM-clause entry for table "badges" 

이 내 모델입니다

class Badge < ActiveRecord::Base 

    has_many :user_badges, :dependent => :destroy 
    has_many :users, :through => :user_badges, :conditions => ["(user_badges.era_id =? and badges.seasonal =?)", GAME_CONFIG["current_era"], true, GAME_CONFIG["current_era"], false] 
end 

올바른 방향으로 나를 가리킬 수 있습니까?

감사합니다.

답변

0
has_many :users, -> { select(badges.*, users.*).where("user_badges.era_id =? and badges.seasonal =?", GAME_CONFIG["current_era"], GAME_CONFIG["current_era"]) }, through: :user_badges 
+0

감사 릭하지만 뭔가가 전에없는 것 같다. "-> {(배지를 선택", 또한 내가 전에 보지 못했다 "->".. 작업 BTW이 응용 프로그램에 난 아직도 레일 2.3을 사용하고 – Augusto

+0

오, 예수님 레일스 2.3 '->'레일 4 기능입니다 [이 게시물 확인] (http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html) & " 커스터마이징 질의 " –

+0

Rails 4에서 구문이 올바르지 만 Rails 2.3에서 작동하기 때문에 작동하지 않을 것입니다. 핵심은 배지 데이터로드를 돕기 위해'select() '를 사용하는 것입니다. –