我想創建兩個有很多關係到相同的目的地表,但我無法覆蓋定義關聯時創建的默認方法名稱欄。如何更改has_through導航關聯的方法名稱?
以下的話:
class User < ApplicationRecord
has_many :conference_attendees, dependent: :destroy
has_many :conference_organizers, dependent: :destroy
has_many :conferences, through: :conference_attendees, class_name: 'attending', dependent: :destroy
has_many :conferences, through: :conference_organizers, source: :conference, dependent: :destroy
class ConferenceOrganizer < ApplicationRecord
alias_attribute :organizers, :users
belongs_to :conference
belongs_to :user
end
class ConferenceAttendee < ApplicationRecord
belongs_to :conference
belongs_to :user
end
class Conference < ApplicationRecord
has_many :conference_attendees, dependent: :destroy
has_many :conference_organizers, dependent: :destroy
has_many :users, through: :conference_attendees, dependent: :destroy
has_many :organizers, through: :conference_organizers, source: :user, dependent: :destroy
我試圖訪問用戶出席了所有會議,然後將所有會議,用戶使用類似下面的組織:
User.find(id: <id>).organizing
User.find(id: <id>).attending
但我無法和
User.find(id: <id>).conferences
默認爲組織會議。我如何獲得參加會議?