This is my take on it:
OLD WAY - has_and_belongs_to_many :my_model
This is an out of date technique to set up the many-to-many table. A
major limitation to this method is that you cannot have any more fields
in the table then the 2 joining fields, and the join table does not use
a primary field key called ‘id’. You can’t sort joined fields very
easily with this method.
This technique is very easy to set up. The table name is the plural
names of the 2 joining tables, in alphabetical order, separated by an
underscore. Table C and B would be BS_CS. The only 2 fields in the join
table would be b_id and c_id.
NEW WAY - has_many :through
This technique allows the join table to have as many fields as you
want. You need a model, for the joining, to make this work. You can just
generate a model. But if you need more fields, you can scaffold. The
join table also gets the primary key field (’id’) that is automatically
generated in most cases.
The joining table can be named what ever you want. The current trend
is to use a table name that just has one word, and usually ends in
-ship, -tion, or -ment. There can be endless hours of debate over the
name of the joining table.
You will need to have the 2 joining table’s foreign key fields in
this table, like the fashion ‘_id’, that are not pluralized.
If you wanted to join table A and table B, an example of the joining
table could be:
TABLES
A
id (integer, primary key)
name (string)
B
id (integer, primary key)
name (string)
AB (many table for joining tables A and B)
id (integer, primary key)
a_id (integer)
b_id (integer)
… (more fields)
The MODELS
A
has_many :ABs
has_many :Bs :through => :ABs
AB
belongs_to :A
belongs_to :B
B
has_many :ABs
has_many :As :through => :ABs
SOME OPTIONS
has_many :mytable, :foreign_key => 'myfield_id',
:class_name => 'myclassname',
:dependent => :destroy