我有以下数据库架构:
alt text http://img843.imageshack.us/img843/3410/databasediagram.png
我希望能够做到这样的事情:
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