0
どちらかのクラスからhas_and_belongs_to_manyによって追加されたメソッドにアクセスしようとすると、2つのモデルのM2Mアソシエーションを作成したい、別の名前空間に作成したい、レールが教えてくれます名前空間モデルの関連付けエラーカラムが見つかりません
のActiveRecord :: StatementInvalid:PG :: UndefinedColumn:ERROR:列namespace_model1s_model2s.model1_idが
Here're私のモデルは存在しません:
スコープ/ model1.rb
class Namespace::Model1 < ActiveRecord::Base
has_and_belongs_to_many :model2s
end
class CreateJoinTableNamespaceModel1sModel2s < ActiveRecord::Migration
def change
create_join_table :namespace_model1s, :model2s do |t|
# t.index [:namespace_model1_id, :model2_id]
# t.index [:model2_id, :namespace_model1_id]
end
end
end
そして、誰がどこで私に言うことができる、だから、結果schema.rb
create_table "namespace_model1s_model2s", id: false, force: :cascade do |t|
t.integer "namespace_model1_id", null: false
t.integer "model2_id", null: false
end
をfinalyこのコマンドを実行してから、移行ファイルを生成
model2.rb
class Model2 < ActiveRecord::Base
has_and_belongs_to_many :namespace_model1s
end
うんざりですか?