Я обошел named_scope и нашел элегантное решение.Итак, я публикую это здесь, так что другие, застрявшие с той же проблемой, также могут получить помощь.Мое решение дает вам возможность получить доступ к любому столбцу модели объединения в ассоциации "многие из них".
Вот решение моей проблемы, приведенное выше:
class Widget < ActiveRecord::Base
has_many :widget_features
has_many :features, :through => :widget_features
def leaf_features
widget_features.leaf_features.map{|widget_feature|widget_feature.feature}
end
end
class WidgetFeature < ActiveRecord::Base
named_scope :leaf_features, :conditions => 'children_features IS NULL'
belongs_to :feature
belongs_to :widget
attr_accessible :children_features, :widget_id, :feature_id
end
Теперь Widget.find_by_id(widget_id).leaf_features
дать вам только те функции, где children_features column is NULL
.