我在这里有一个问题,我正在链接性别+类别+子类别的产品种子。
种子
g = Gender.create(:gender => 'Man')
g.categories.create(:name => "Clothes")
g = Gender.create(:gender => 'Woman')
g.categories.create(:name => "Accessories")
m = Category.find_by_name("Clothes")
m.subcategories.create(:name => "T-shirts" )
f = Category.find_by_name("Accessories")
f.subcategories.create(:name => "Rings" )
模型关系
性别
has_many:categories has_many:subcategories,through::categories
accepts_nested_attributes_for:categories,:subcategories
attr_accessible:gender,:categories_attributes,
:subcategories_attributes
分类
belongs_to:性别
has_many:subcategories
accepts_nested_attributes_for:subcategories
attr_accessible:name,:gender_id
子类别
问题是:每次创建种子时,都会在Man子类别表上创建Woman子类别。有人可以帮忙吗?
感谢' S