Try changing the name of the join table to customergrous_customers.
Also with a straight habtm the join table doesn’t need an ID column,
though I don’t know off hand if it breaks anything to have one.
I already switched both parts to customergroups_customer, no effect. I
now did remove the id column, because I don’t really need it, but
still no luck.
The join table should be called customergroups_customers (notice the s
on the end of customers)
Actually I’m pretty sure that the default table name would be
customers_customergroups It get’s generated by the sort order of the
(singular) class names and “customer” < “customergroup”
Of course it can be explicitly set using the :join_table option on the
:has_and_belongs_to_many relationship.
Personally I’ve ditched habtm and the general drift in Rails
development is to avoid it. If you use an explicit join table it’s a
little easier to manage (IMO) and you gain the benefit of easily
handling attributes on the association. Just to reduce the long names
I’d use something like this:
The join table should be called customergroups_customers (notice the s
on the end of customers) and should have 2 columns customer_id and
customergroup_id their should be no primary key or any other column.
in your customer.rb file you should have as the second line
has_and_belongs_to_many :customergroups
and in your customergroup.rb file you should have
has_and_belongs_to_many :customers
(notice the models have singular names and the associations have
pluralised names)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.