Использование вложенных атрибутов на обеих сторонах ассоциации с inverse_of - PullRequest
0 голосов
/ 10 июня 2019

Версия моего рельса - 4.1.16.У меня есть связь «один ко многим» с вложенными атрибутами на обеих сторонах моделей и опция inverse_of в обеих моделях.

class Post
  has_many :comments, inverse_of: :post
  accepts_nested_attributes_for :comments
end 


class Comment
  belongs :post, inverse_of: :comments
  accepts_nested_attributes_for :post
end 

Это вызывает бесконечную рекурсию (глубокая ошибка на уровне стека) при сохранениизапись.

Пожалуйста, найдите обратный след для того же:

activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `block in nested_records_changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:286:in `any?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:286:in `nested_records_changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:265:in `changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `block (2 levels) in nested_records_changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `any?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `block in nested_records_changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:286:in `any?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:286:in `nested_records_changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:265:in `changed_for_autosave?'
  state_machine (1.2.0) lib/state_machine/integrations/active_record.rb:491:in `changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `block (2 levels) in nested_records_changed_for_autosave?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `any?'
  activerecord (4.1.16) lib/active_record/autosave_association.rb:289:in `block in nested_records_changed_for_autosave?'

Я смотрел в вопросе здесь .Удаление inverse_of решает проблему.Но мне нужно использовать опцию inverse_of.Есть ли обходной путь для этой проблемы?

...