我有以下数据库架构:
我希望能够做这样的事情:
dog.head << Feature.new(...)
dog.tail << Feature.new(...)
我是 Rails 新手,所以我并不总是 100% 确定我在写什么,但我尝试遵循 Dog 类的声明,但失败了:):
class Dog < ActiveRecord::Base
has_many :features, :through=>:dog_features
has_many :head_features, :through=>:dog_features, :class_name=>'Feature', :conditions=>{:group=>1}
has_many :tail_features, :through=>:dog_features, :class_name=>'Feature', :conditions=>{:group=>2}
end