Ruby on rails Rails 4.1.x HABTM未定义方法';外键';

Ruby on rails Rails 4.1.x HABTM未定义方法';外键';,ruby-on-rails,ruby-on-rails-4.1,Ruby On Rails,Ruby On Rails 4.1,以下定义适用于Rails 4.0.x及更低版本: module Gemgento class Product < ActiveRecord::Base has_and_belongs_to_many :stores, -> { distinct }, join_table: 'gemgento_stores_products', class_name: Gemgento::Store end end 在Rails 4.1中搜索了任何记录在案的对HABTM的更

以下定义适用于Rails 4.0.x及更低版本:

module Gemgento
   class Product < ActiveRecord::Base
      has_and_belongs_to_many :stores, -> { distinct }, join_table: 'gemgento_stores_products', class_name: Gemgento::Store
   end
end

在Rails 4.1中搜索了任何记录在案的对HABTM的更改之后,我找不到任何东西。4.0中也没有弃用警告。原来
:class_name
必须定义为字符串

module Gemgento
   class Product < ActiveRecord::Base
      has_and_belongs_to_many :stores, -> { distinct }, join_table: 'gemgento_stores_products', class_name: 'Gemgento::Store'
   end
end
模块Gemgento
类产品{distinct},join_表:'gemgento_商店_产品',类名:'gemgento::商店'
结束
结束

此更改不影响任何其他关联。但是,从现在起,确保始终使用字符串可能是件好事。

谢谢,这为我省去了很多麻烦,所以我想指出,使用
class:Gemgento::Store
class\u name:Gemgento::Store.name
来避免输入错误是很有用的
module Gemgento
   class Product < ActiveRecord::Base
      has_and_belongs_to_many :stores, -> { distinct }, join_table: 'gemgento_stores_products', class_name: 'Gemgento::Store'
   end
end