0
레일즈가 말해주는 두 클래스에서 has_and_belongs_to_many가 추가 한 메소드에 액세스하려고 할 때 두 모델에 대해 서로 다른 네임 스페이스에있는 M2M Association을 만들고 싶습니다.Namespaced Model Associations 오류 열을 찾을 수 없음
액티브 :: StatementInvalid는 : PG : UndefinedColumn : 오류 : 열 namespace_model1s_model2s.model1_id는
바로 여기에 내 모델이 존재하지 않습니다
범위/model1.rb을
class Namespace::Model1 < ActiveRecord::Base
has_and_belongs_to_many :model2s
end
이 명령
rails g migration CreateJoinTableNamespaceModel1sModel2s namespace_model1 model2
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을 실행에서
model2.rb
class Model2 < ActiveRecord::Base
has_and_belongs_to_many :namespace_model1s
end
생성 된 마이그레이션 파일
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
그래서 아무도 나를 어디를 알 수 있습니다 놀림?