0

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.

Aryabhima A. Rahman
  • 375
  • 1
  • 5
  • 10
  • 1
    Which line causes the error? Do you have `kulits_efloresensi_kulits` somewhere in your code? Do you have any more lines in the models? – Vasilisa Mar 15 '20 at 08:17
  • Please add more context: the exception trace, what do you do in order to reproduce the error. – ka8725 Mar 15 '20 at 19:28
  • @Vasilisa i checked my code again, indeed i have that `kulits_efloresensi_kulits` in my code. I changed it to `efloresensi_kulits_kulits` then it was fixed. Thank you very much. But I still wonder why it did not raise an error in Rails 5. – Aryabhima A. Rahman Mar 16 '20 at 02:53
  • @AryabhimaA.Rahman happy to help :) We can try to answer 'why it did not raise an error in Rails 5' if you add the corresponding part of code, which contained kulits_efloresensi_kulits – Vasilisa Mar 16 '20 at 04:57

0 Answers0