没错。这只是拒绝工作。在这里呆了几个小时。Rails 4找不到关联has_many,通过:关系错误
相册样板
功能模型
class Feature < ActiveRecord::Base
has_many :albums, through: :join_table1
end
join_table1模式
class JoinTable1 < ActiveRecord::Base
belongs_to :features
belongs_to :albums
end
个join_table1模式
album_id | feature_id
相册模式
id | title | release_date | genre | artist_id | created_at | updated_at | price | image_path
特征模式
id | feature | created_at | updated_at
在耙测试数据库,并运行这个集成测试:
require 'test_helper'
class DataFlowTest < ActionDispatch::IntegrationTest
test "create new user" do
album = albums(:one)
feature = features(:one)
album.features
end
end
我得到
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :join_table1 in model Album
这是为什么?
我不认为连接表的命名约定与has_many通过关系有关系。 – Starkers
您不能拥有2个名称为Feature的模型,这是最重要的。 – biomancer
另外,activerecord模型的名称应该与其表名相对应。 – biomancer