HABTM 관계의 모델은 MaintenanceOrder
및 Maintenance
입니다.HABTM의 명명 규칙 문제
I have two models that are similar, and I'm wondering if this is the cause of the error?
@maintenance.maintenances
=> ActiveRecord::StatementInvalid: Could not find table 'maintenance_orders_maintenances'
@maintenance_order.maintenances
=> ActiveRecord::StatementInvalid: Could not find table 'maintenance_orders_maintenances'
반면 :
create_table :maintenances_maintenance_orders, id: false do |t|
t.belongs_to :maintenance, index: true
t.belongs_to :maintenance_order, index: true
end
을 그럼 난 오류가 발생합니다 : 마이그레이션이 조인 테이블을 생성에 관해서
create_table :maintenance_orders do |t|
...
end
create_table :maintenances do |t|
...
end
다음과 같이 선언했다, 나는 경우 것으로 나타났습니다 오류가있는 경우 다음과 같은 조인 테이블을 제안합니다.
create_table :maintenance_orders_maintenances, id: false do |t|
t.belongs_to :maintenance_order, index: true
t.belongs_to :maintenance, index: true
end
모두 정상적으로 작동합니다. 그러나 HABTM의 정의에 따라 모델이 선언 된 순서가 중요하지 않기 때문에이 질문을 던지고 있습니다. 그래서 ... 이름이 너무 비슷해서 이런 식으로해야하는 뱀 사건이 있습니다. (아마도 maintenances_maintenance
이 매우 혼란 스럽습니다) 아니면 ...? 이것에 대한 어떤 규칙?
기본적으로 레일스는 테이블 이름을 알파벳순으로 정렬합니다. 'maintenance_order'는'maintenances' 앞에옵니다. 그래서 : : maintenance_orders_maintenances'는 레일스가 테이블 이름을 기대하는 것입니다 –