Home > database >  rails 6.1.4 ArgumentError: Unknown key: :table_name
rails 6.1.4 ArgumentError: Unknown key: :table_name

Time:01-30

I'm getting the error below after my rails upgrade from 6 to 6.1. on an association.

Unknown key: :table_name. Valid keys are: :class_name, :anonymous_class, :primary_key, :foreign_key, :dependent, :validate, :inverse_of, :strict_loading, :autosave, :before_add, :after_add, :before_remove, :after_remove, :extend, :counter_cache, :join_table, :index_errors, :ensuring_owner_was

This is the code in my model

has_many :cloud_provider_relationships, table_name: 'ecosystems_cloud_providers',
                                          class_name: 'EcosystemCloudProvider'
  has_and_belongs_to_many :cloud_providers, through: :cloud_provider_relationships,
                          join_table: 'ecosystems_cloud_providers'

Any help would be greatly appreciated.

CodePudding user response:

has_many never took a :table_name key as an argument. You can safely remove it. :class_name is enough to map rows from cloud_provider_relationships table to EcosystemCloudProvider class

you can check all available options here https://apidock.com/rails/v6.1.3.1/ActiveRecord/Associations/ClassMethods/has_many

  •  Tags:  
  • Related