레일에서 기본 모델 연결을 시도하고 있습니다. 기본적으로 item_id 및 user_id를 저장하는 List 테이블이 있습니다.레일 기본 연결
한 사용자가 여러 개의 "목록 항목"을 만들 수 있습니다.
올바른 방법인가요?
감사합니다.
class Item < ActiveRecord::Base
has_many :users, :through => :lists
end
class User < ActiveRecord::Base
has_many :items, :through => :lists
end
class List < ActiveRecord::Base
belongs_to :user
belongs_to :item
end
네, 그게 효과가 있습니다. 또는'belongs_to : list' 아이템,'belongs_to : user'와'has_many : items' 아이템, 사용자'has_many : lists' 아이템을 가질 수 있습니다. –