0
을 가지고 다음과 같은 모델 협의체 Active Record Associations 문서가 자기 설명적인 것으로 보인다모델 협회에 속한 대한
User can purchase many Items
Items can be purchased by many users
Items have many categories
을 가지고 다음과 같은 모델 협의체 Active Record Associations 문서가 자기 설명적인 것으로 보인다모델 협회에 속한 대한
User can purchase many Items
Items can be purchased by many users
Items have many categories
에게 어떻게해야!
당신은User
와
Item
사이
has_many...through
관계, 그리고
Item
및
Category
사이
has_many
관계가 필요합니다.
# app/models/user.rb
class User < ActiveRecord::Base
has_many :purchases
has_many :items, through: :purchases
end
# app/models/item.rb
class Item < ActiveRecord::Base
has_many :purchases
has_many :users, through: :purchases
has_many :categories
end
# app/models/purchase.rb
class Purchase < ActiveRecord::Base
belongs_to :user
belongs_to :item
end
# app/models/category.rb
class Category < ActiveRecord::Base
belongs_to :item
end
도움 주셔서 감사합니다. –