나는 골프 관련 웹 사이트를 개설하고 있습니다. 몇 가지 모델이 있지만 코스를 통합하려고 할 때 문제가 발생했습니다. 골프 클럽에 골프 코스가 두 개 이상이거나 코스 이름이 골프 클럽과 다른 경우 코스는 코스 이름을 나타냅니다 (예 : Troon North Golf Club에는 두 개의 코스, 피나클 및 기념비가 있음). 연결을 만드는 방법을 모르겠다.활기찬 기록 계열
class Tournament < ActiveRecord::Base
has_many :rounds, dependent: :destroy
has_many :clubs, through: :rounds, dependent: :destroy
// do I need this to be able to do @tournament.rounds.first.course.first.name?
has_many :courses, through: :rounds
class Round < ActiveRecord::Base
belongs_to :tournament
belongs_to :club
// not all rounds will have a course
has_many :courses, :through => :rounds
class Club < ActiveRecord::Base
has_many :rounds, dependent: :destroy
has_many :tournaments, :through => :rounds, dependent: :destroy
has_many :club_images, dependent: :destroy
// not all clubs will have a course
has_many :courses, dependent: :destroy
class Course < ActiveRecord::Base
belongs_to :club
belongs_to :rounds
나는 다음을 사용하여 시도했다. 나는 그것을 생각했다 : through는 http://guides.rubyonrails.org/association_basics.html, 2.4 절을 읽은 후에 사용할 수있다.
create_table "clubs", :force => true do |t|
t.string "name"
t.string "address"
t.string "city"
t.string "state"
t.string "zip"
t.string "phone"
t.string "website"
t.datetime "created_at"
t.datetime "updated_at"
t.string "logo_file_name"
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
end
create_table "courses", :force => true do |t|
t.integer "club_id"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "rounds", :force => true do |t|
t.integer "tournament_id"
t.integer "club_id"
t.integer "course_id"
t.datetime "start_time"
t.datetime "checkin_time"
t.datetime "entry_deadline"
t.decimal "member_fee"
t.decimal "guest_fee"
t.boolean "scoring"
t.boolean "lunch_included"
t.text "comments"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "tournaments", :force => true do |t|
t.string "name"
t.date "start_date"
t.date "end_date"
t.text "comments"
t.text "practice_round_comments"
t.datetime "created_at"
t.datetime "updated_at"
end
내가 round.courses @ 실행하려고
, 나는 다음과 같은 메시지가 얻을 - 액티브 :: HasManyThroughAssociationNotFoundError을 : 모델 라운드에서 라운드 : 연결을 찾을 수 없습니다.나는 혼란스럽고 잘 모르겠다. 어떤 도움을 주시면 감사하겠습니다. 감사!
단 하나의 오타를 보내 주셔서 감사합니다. 어쩌면 내 디자인에 결함이있는 것일 수도 있지만 코스가 실제로 클럽 설치의 일부이기 때문에 나는 round_id를 지정하지 않았습니다. 1 년에 한 번 Pinnacle 코스에서 Troon North에서 토너먼트를 개최합니다. Round_Course 테이블처럼 그들을 연결하는 다른 모델을 생성해야합니까? – Memo