-2
私はジョインテーブルを持っています。複数のモジュールをジョインテーブルでレールする
にすべての作業罰金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
プロフィール:イベントと場所のためのThingLocationとは別のmuduleを追加したいです私が第3のモジュールを追加したいときまで:結合テーブルを通して利用可能な場所を使用するためのプロファイルThingL 。 thing_locations.rbから:「イベントbelongs_toの」を解決しますが、これは間の関連付けを削除します、私はそれがエラーをスローフォームプロファイル更新に場所をつかむしようとすると
は
はを削除「イベントが存在しなければなりません」プロファイルやイベント
....新しいモデルを追加した後:プロファイル
thing_location.rb
参加モジュールに: "真のオプション" を追加するだけでレール5で見つかっ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