J'ai une table Join; ThingLocation pour l'événement et l'emplacement et veut ajouter un autre mudule: ProfilRails plusieurs modules avec une table de jointure
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
Tout beau travail jusqu'à ce que je voulais ajouter un troisième module: Profil pour utiliser les emplacements disponibles à travers la table de jointure ThingL ocation.
Lorsque je tente de saisir l'emplacement dans la mise à jour du profil forme qu'il jette l'erreur « événement doit exister »
Retrait « belongs_to: événement » du thing_locations.rb résout le mais cela supprimera l'association entre profils et événements
.... Après avoir ajouté un nouveau modèle: profils
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