Right. Questo semplicemente si rifiuta di lavorare. Sono stato a questo per ore.Rails 4 Impossibile trovare l'associazione has_many, tramite: relationship error
album modello
class Album < ActiveRecord::Base
has_many :features, through: :join_table1
end
caratteristiche modello
class Feature < ActiveRecord::Base
has_many :albums, through: :join_table1
end
join_table1 modello
class JoinTable1 < ActiveRecord::Base
belongs_to :features
belongs_to :albums
end
schema join_table1
album_id | feature_id
album schema
id | title | release_date | genre | artist_id | created_at | updated_at | price | image_path
caratteristiche dello schema
id | feature | created_at | updated_at
Su rastrellando il database di test, e l'esecuzione di questo test di integrazione:
require 'test_helper'
class DataFlowTest < ActionDispatch::IntegrationTest
test "create new user" do
album = albums(:one)
feature = features(:one)
album.features
end
end
ottengo
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :join_table1 in model Album
Perché è questo?
Non penso che la convenzione di denominazione della tabella di join abbia una relazione has_many, through. – Starkers
Non è possibile avere 2 modelli con il nome Feature, questo è ciò che conta. – biomancer
Inoltre, il nome di un modello activerecord deve corrispondere al nome della tabella. – biomancer