0

如何为有父亲、母亲和最多两名监护人的孩子建立入学协会?

我知道有很多方法可以设置它,但你会怎么做呢?我不太确定如何设置监护人。我目前正在考虑两种选择,也许你可以推荐第三种。

选项1

Enrollments
belongs_to child
belongs_to father
belongs_to mother

Children
has_one enrollment
has_one father
has_one mother

Father
has_many enrollments
has_many children

Mother
has_many enrollments
has_many children

选项 2

Enrollments
has_and_belongs_to_many adults

Adults
has_and_belongs_to_many enrollments
has_many children
# would have a "relationship: father, mother, guardian"

Children
has_one enrollment
has_one father
has_one mother
4

1 回答 1

2

如果我是你,我会检查 has_many :through。

成年人

has_many children, :through => enrollments

孩子们

has many adults, :through => enrollments
于 2012-07-11T20:30:53.707 回答