-2
我有一個連接表; ThingLocation的事件和地點,想要添加另一個mudule:簡介用連接表導軌多個模塊
thing_location.rb
class ThingLocation < ActiveRecord::Base
belongs_to :event
belongs_to :location
end
event.rb
class Event < ApplicationRecord
has_many :thing_locations
has_many :locations, through: :thing_locations
end
location.rb
class Location < ApplicationRecord
has_many :thing_locations
has_many :events, through: :thing_locations
end
所有做工精細直到我想添加第三個模塊:配置文件通過連接表ThingL使用可用的位置ocation。
當我嘗試在配置文件更新搶位置的形式,它拋出錯誤「事件必須存在」
刪除:從thing_locations.rb「belongs_to的事件」解決,但是這將刪除之間的關聯型材和事件
....添加新的模型之後:配置文件
thing_location.rb
class ThingLocation < ActiveRecord::Base
belongs_to :event
belongs_to :location
belongs_to :profile
end
event.rb
class Event < ApplicationRecord
has_many :thing_locations
has_many :locations, through: :thing_locations
belongs_to:profile
end
location.rb
class Location < ApplicationRecord
has_many :thing_locations
has_many :events, through: :thing_locations
has_many :profiles, through: :thing_locations
end
profile.rb
class Profile < ApplicationRecord
has_many :thing_locations
has_many :locations, through: :thing_locations
has_many :hows, dependent: :destroy
end