Dobrze. To po prostu odmawia pracy. Byłem w tym przez wiele godzin.Szyny 4 Nie można znaleźć powiązania has_many, przez: błąd relacji
modelu album
class Album < ActiveRecord::Base
has_many :features, through: :join_table1
end
cechy modelu
class Feature < ActiveRecord::Base
has_many :albums, through: :join_table1
end
join_table1 modelu
class JoinTable1 < ActiveRecord::Base
belongs_to :features
belongs_to :albums
end
join_table1 schematu
album_id | feature_id
albumy schematu
id | title | release_date | genre | artist_id | created_at | updated_at | price | image_path
cechy schematu
id | feature | created_at | updated_at
Upon grabienie bazę testową, a uruchomienie tego testu integracyjnego:
require 'test_helper'
class DataFlowTest < ActionDispatch::IntegrationTest
test "create new user" do
album = albums(:one)
feature = features(:one)
album.features
end
end
uzyskać
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :join_table1 in model Album
Dlaczego tak jest?
Nie sądzę, że konwencja nazewnictwa tabeli złączeń ma znaczenie w związku. – Starkers
Nie możesz mieć 2 modeli o nazwie Feature, to się liczy. – biomancer
Ponadto nazwa modelu aktywnego rekordu powinna odpowiadać nazwie tabeli. – biomancer