0

、、、の3 つのモデルUserSupplierありCompanyます。andとandの間には一対多関係があります (ユーザーは多くのサプライヤーを持ちますが、サプライヤーは 1 人のユーザーに属します)。Rails 3でそのような関連付けを作成する正しい方法は何ですか? また、UserSupplierCompanySupplierUser has_many Courses through UserCourses

4

2 に答える 2

1

正しく理解できていれば、次のようになります。

ユーザー:

has_many :suppliers
has_many :user_courses
has_many :users, through: :user_courses

サプライヤー:

belongs_to :user
belongs_to :company

会社:

has_many :suppliers
于 2012-08-03T06:12:06.950 に答える
1

Courses が User、Company、Supplier とともに別のモデルである場合、次のように動作するはずです。

ユーザー: has_many :suppliers has_many :user_courses has_many :courses, :through => :user_courses

サプライヤー: 所属先 :ユーザー 所属先 :会社

会社: has_many :suppliers

コース: has_many :user_courses has_many :users, :through => :user_courses

于 2012-08-03T14:11:35.807 に答える