我有自我参考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?
我哪里弄错了?谢谢。