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