error relation does not exist rails has and belongs to many code example

Example: rails has_many_and_belongs_to PG::UndefinedTable: Error: relation does not exist

# Migration file should use create_join_table() rather than create_table
# example:
create_join_table :assemblies :parts do |t|
  t.index %i[part_id assembly_id]
  t.index %i[assembly_id part_id]
end

# sources: https://apidock.com/rails/v6.0.0/ActiveRecord/ConnectionAdapters/SchemaStatements/create_join_table
# https://stackoverflow.com/questions/28902916/pgundefinedtable-error-relation-categories-posts-does-not-exist

Tags:

Ruby Example