0

나는 자기 참조 habtm 어소시에이션 있습니다.레일 HABTM 협회

class Label < AR::B 
    has_and_belongs_to_many :a_label, :class_name => "Label", 
      :join_table => "a_labels", 
      :foreign_key => "label_id", 
      :association_foreign_key => "a_label_id", 
      :uniq => true 
end 

하지만 난 (squeel와) 쿼리를 만들 때 :

Label.select{:title}.where do 
     id.in(Label.select{:a_label_id}.joins(:a_labels).where{ 
      labels.title.in(list) 
      }) 

스키마 :

labels: 
id | title | description | created_at 

a_labels 
label_id | a_label_id  

내가 오류가있어 : 내가 잘못

ActiveRecord::ConfigurationError: 
    Association named 'a_labels' was not found; perhaps you misspelled it? 

입니까? 감사합니다. .

답변

1

"s"를 연결 이름에 추가해야하는 것처럼 보입니다. "a_label"대신 "a_labels"로 변경하십시오.

class Label < AR::B 
    has_and_belongs_to_many :a_labels, ... 
    ... 
end 
+0

더 복잡한 쿼리가 있습니다. 나는 질문을 업데이트했다. – Mike