У меня есть модель ActiveRecord с именем Bill, которая имеет полиморфную ассоциацию: bill_elements
has_many :sites, through: :bill_elements, source: :element, source_type: 'Site'
has_many :primary_billing_points, through: :bill_elements, source: :element, source_type: 'PrimaryBillingPoint'
Я хочу убедиться, что выбран хотя бы один элемент bill и, следовательно, добавлено
validates :bill_elements, length: { minimum: 1 }
Однако, как только пользователь нажимает сохранить, я получаю сообщение об ошибке: Polymorphic association does not support to compute class.
Контроллер выполняет @bill.update(bill_attributes)
Похоже, проверки не выполняются.Я попытался добавить туда пользовательскую проверку с помощью оператора Put, и я вижу инструкцию Put, если обновляю любое другое поле, но не удаляю связанные сайты / основные пункты выставления счетов.
Вот полная трассировка стека:
ActiveRecord::Reflection::BelongsToReflection#compute_class
activerecord (5.2.1) lib/active_record/reflection.rb, line 420
ActiveRecord::Reflection::BelongsToReflection#klass
activerecord (5.2.1) lib/active_record/reflection.rb, line 379
ActiveRecord::Associations::HasManyThroughAssociation#delete_records
composite_primary_keys (11.0.3) lib/composite_primary_keys/associations/has_many_through_association.rb, line 22
ActiveRecord::Associations::HasManyThroughAssociation#remove_records
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 398
ActiveRecord::Associations::HasManyThroughAssociation#remove_records
activerecord (5.2.1) lib/active_record/associations/has_many_through_association.rb, line 108
block in ActiveRecord::Associations::HasManyThroughAssociation#delete_or_destroy
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 391
block in ActiveRecord::Associations::HasManyThroughAssociation#transaction
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 134
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#transaction
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb, line 252
Site.transaction
activerecord (5.2.1) lib/active_record/transactions.rb, line 212
ActiveRecord::Associations::HasManyThroughAssociation#transaction
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 133
ActiveRecord::Associations::HasManyThroughAssociation#delete_or_destroy
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 391
ActiveRecord::Associations::HasManyThroughAssociation#delete
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 188
ActiveRecord::Associations::HasManyThroughAssociation#replace_records
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 412
block in ActiveRecord::Associations::HasManyThroughAssociation#replace
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 250
block in ActiveRecord::Associations::HasManyThroughAssociation#transaction
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 134
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#transaction
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb, line 252
Site.transaction
activerecord (5.2.1) lib/active_record/transactions.rb, line 212
ActiveRecord::Associations::HasManyThroughAssociation#transaction
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 133
ActiveRecord::Associations::HasManyThroughAssociation#replace
activerecord (5.2.1) lib/active_record/associations/collection_association.rb, line 250
ActiveRecord::Associations::HasManyThroughAssociation#ids_writer
composite_primary_keys (11.0.3) lib/composite_primary_keys/associations/collection_association.rb, line 26
Bill#site_ids=
activerecord (5.2.1) lib/active_record/associations/builder/collection_association.rb, line 65
Bill#_assign_attribute
activemodel (5.2.1) lib/active_model/attribute_assignment.rb, line 51
block in Bill#_assign_attributes
activemodel (5.2.1) lib/active_model/attribute_assignment.rb, line 44
Bill#_assign_attributes
activemodel (5.2.1) lib/active_model/attribute_assignment.rb, line 43
Bill#_assign_attributes
activerecord (5.2.1) lib/active_record/attribute_assignment.rb, line 23
Bill#assign_attributes
activemodel (5.2.1) lib/active_model/attribute_assignment.rb, line 35
block in Bill#update
activerecord (5.2.1) lib/active_record/persistence.rb, line 427
block in Bill#with_transaction_returning_status
activerecord (5.2.1) lib/active_record/transactions.rb, line 387
block in ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#transaction
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb, line 254
block in ActiveRecord::ConnectionAdapters::TransactionManager#within_new_transaction
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/transaction.rb, line 239
ActiveSupport::Concurrency::LoadInterlockAwareMonitor#mon_synchronize
/Users/jeremynagel/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/monitor.rb, line 214
ActiveRecord::ConnectionAdapters::TransactionManager#within_new_transaction
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/transaction.rb, line 236
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#transaction
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb, line 254
Bill.transaction
activerecord (5.2.1) lib/active_record/transactions.rb, line 212
Bill#with_transaction_returning_status
activerecord (5.2.1) lib/active_record/transactions.rb, line 385
Bill#update
activerecord (5.2.1) lib/active_record/persistence.rb, line 426
block in Admin::BillsController#update
app/controllers/admin/bills_controller.rb, line 84
Admin::BillsController#respond_to
actionpack (5.2.1) lib/action_controller/metal/mime_responds.rb, line 197
Admin::BillsController#update
app/controllers/admin/bills_controller.rb, line 83
Я использую Rails 5.2.