I have two tables with a many to many relationship that I am using has_and_belongs_to_many to define the association.

class Foo < ActiveRecord::Base
  ...
  has_and_belongs_to_many :bar
  ...
end

class Bar < ActiveRecord::Base
  ...
  has_and_belongs_to_many :foo
  ...
end

I also have the class defined to represent the join table

class BarFoo < ActiveRecord::Base
  ...
  belongs_to :foo
  belongs_to :bar
  ...
end

When I run rake db:seed I get the following error:

Primary key is not allowed in a has_and_belongs_to_many join table (bar_foo)

If I edit the database and remove the primary key field (ID) from the bar_foo table and then rerun rake db:seed everything works as desired.

Given the above, what is the preferred means of creating join tables in rails with no primary key?

I also tried using "has_many :bars, :through => :foo" and vise versa but got an error message something like "undefined method 'klass' for nil:NilClass".

Edit
Report