After upgrading my app to Rails 6, model which has many to many relationship causes an error saying that
Association named 'kulits_efloresensi_kulits' was not found on Kulit; perhaps you misspelled it?
On Rails 5 it was working fine. Here are the models:
class Kulit < ApplicationRecord
has_and_belongs_to_many :efloresensi_kulits
belongs_to :physical_check, optional: true
class EfloresensiKulit < ApplicationRecord
has_and_belongs_to_many :kulits
The error occurs on line:
@physical_checks.reverse.each do |data|
I found that the join table was named 'efloresensi_kulits_kulits', so I tried to define it in the model
class Kulit < ApplicationRecord
has_and_belongs_to_many :efloresensi_kulits, join_table: "efloresensi_kulits_kulits"
class EfloresensiKulit < ApplicationRecord
has_and_belongs_to_many :kulits, join_table: "efloresensi_kulits_kulits"
But the error still occurs. How can I fix this error?
FIXED
apparently kulits_efloresensi_kulits
was mentioned in the code, I changed it to correct name and it was fixed.
But I still wonder why it did not raise an error in Rails 5.